设为首页 加入收藏

TOP

read命令读取用户输入
2015-08-31 21:23:05 来源: 作者: 【 】 浏览:19
Tags:read 命令 读取 用户 输入

read命令用于从终端或文件中读取用户输入,它读取整行输入,如果没有指定名称,读取的行被赋值给内部变量REPLY。
read命令常用选项:-a,-p,-s,-t,-n


$read
hello
$echo $REPLY
hello


$read answer
hello
$echo $answer
hello


$read first second third
chen xiaopang panda
$echo $first $second $third
chen xiaopang panda


$read -p "Enter your name:" name
Enter your name:chenxiaopang
$echo $name
chenxiaopang


$read -a friends
Tom Mike Jack
$echo ${friends[*]}
Tom Mike Jack


$read -t 5 choice //限定5秒钟内输入变量值,否则,不管用户是否输入,read命令返回非零值


$read -n1 -p 'Enter your Choice (y/n): ' choice
$echo $choice
y


$read -s name


cat test.txt | while read line
do


done?


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Java中如何在Arraylist中实现冒泡.. 下一篇在调用Qt库来实现功能过程中的一..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: