首页 > 代码库 > shell之read的使用
shell之read的使用
read命令用于接收键盘的标准输入以及其它文件的输入,得到输入后,read命令会将数据放到一个标准变量中。
示例 1:
#!/bin/bash
read -s -p "Enter you password: " password #-s:不显示输入,-p:在read命令行指
echo "Hello,your password is $password" 定一个提示
示例 2:
#!/bin/bash
echo -n "Enter your name: "
read name #从键盘输入
echo "Hello! $name"
#!/bin/bash
read -t 5 -p "Enter your name: " name #-t:设定时间限制
echo "This is $name"
示例 3:读行
#!/bin/bash
file=/etc/fstab
i=1
cat $file | while read line
do
echo $i###$line
((i++))
done
本文出自 “一万年太久,只争朝夕” 博客,请务必保留此出处http://zengwj1949.blog.51cto.com/10747365/1924434
shell之read的使用
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。