通过使用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

相关文章:

  • 2022-12-23
  • 2021-06-02
  • 2021-09-14
  • 2021-11-22
  • 2021-10-15
猜你喜欢
  • 2022-12-23
  • 2021-12-07
  • 2022-01-24
  • 2021-12-08
  • 2021-12-10
  • 2022-12-23
  • 2021-12-18
相关资源
相似解决方案