Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1440899
  • 博文数量: 165
  • 博客积分: 2068
  • 博客等级: 上尉
  • 技术积分: 2102
  • 用 户 组: 普通用户
  • 注册时间: 2011-08-27 16:07
文章分类

全部博文(165)

文章存档

2018年(1)

2017年(22)

2016年(9)

2015年(22)

2014年(8)

2013年(25)

2012年(53)

2011年(25)

分类: 系统运维

2015-10-11 10:34:41

read是一个重要的bash命令,用来从键盘或标准输入读取文本。
read可以以交互的形式读取文本,也可以以不敲回车键方式读取文本。
下面来看下read在不敲回车键时读取文本的几种常用方法。

1. 从输入读取n个字符并存入variable_name
用法:read -n number_of_chars variable_name
chicol@debian:~/scripts$ read -n 4 var
testchicol@debian:~/scripts$
testchicol@debian:~/scripts$ echo $var
test
chicol@debian:~/scripts$ 
2. 无回显方式读取密码
chicol@debian:~/scripts$ read -s var
chicol@debian:~/scripts$ echo $var
1234567890
chicol@debian:~/scripts$ 
3. 显示提示信息
chicol@debian:~/scripts$ read -p "Enter Password:" var
Enter Password:1234567890
chicol@debian:~/scripts$ $echo $var
-bash: 1234567890: command not found
chicol@debian:~/scripts$ echo $var
1234567890
4. 用特定界定符作为输入行的结束
chicol@debian:~/scripts$ read -d ":" var
hello:chicol@debian:~/scripts$ echo $var
hello
chicol@debian:~/scripts$ 

阅读(973) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~