Shell的输入输出
通过使用read命令,可以实现从终端中输入内容后输出或执行运算
1 #!/bin/bash 2 #Author: blacksonny 3 #Copyright (c) 4 #Script follows here: 5 6 echo "How old are you?" 7 read age 8 echo "age is " $age
以上代码会首先输出一个 [How old are yoy?],这时终端等待输入,当我们输入18这个数字(会将18赋值给age)并键入回车后,屏幕输出结果为age is 18
如下运行结果:
kk@kk-pc ~/shell $ sh ./inout.sh How old are you? 18 age is 18