1.read命令
read从键盘上读取数据付给变量,可以将多组数据赋给多个变量,数据与变量是一一对应的,分为下面三种情况:
一、变量个数 == 数据个数,则依次一一赋值。
[bestcoder@localhost test1]$ read m1 m2 a b [bestcoder@localhost test1]$ echo $m2 b [bestcoder@localhost test1]$ echo $m1 a
[bestcoder@localhost test1]$ read m1 m2 m3 a b [bestcoder@localhost test1]$ echo $m1 a [bestcoder@localhost test1]$ echo $m2 b [bestcoder@localhost test1]$ echo $m3
[bestcoder@localhost test1]$ read m1 m2 a b c [bestcoder@localhost test1]$ echo $m1 a [bestcoder@localhost test1]$ echo $m2 b c
常见的一个命令,可显示字符串,也可显示变量对应的值。
注意:
选项 -e 是很实用的,其后可以附带转义字符实现各种功能, 选项-n也有同样效果。
\a 响铃报警
[bestcoder@localhost test1]$ echo -e "this is a test \a"
[bestcoder@localhost test1]$ echo -e "this is a test **\b##" this is a test *##
[bestcoder@localhost test1]$ echo -e "this is a test ->\c" this is a test ->[bestcoder@localhost test1]$