您的位置:首页 > 运维架构 > Linux

Linux战地日记——输入输出命令

2015-09-11 22:44 495 查看
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


2.echo命令
常见的一个命令,可显示字符串,也可显示变量对应的值。

注意:

选项 -e 是很实用的,其后可以附带转义字符实现各种功能, 选项-n也有同样效果。

\a 响铃报警

[bestcoder@localhost test1]$ echo -e "this is a test \a"


\b 退出一个字符位置

[bestcoder@localhost test1]$ echo -e "this is a test **\b##"
this is a test *##


\c 出现在参数最后未知,并且输入信息继续在该行后面

[bestcoder@localhost test1]$ echo -e "this is a test ->\c"
this is a test ->[bestcoder@localhost test1]$
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: