42. 如何让 Shell 就脚本得到来自终端的输入?

read 命令可以读取来自终端(使用键盘)的数据。read 命令得到用户的输入并置于你给出的变量中。例子如下:

  1. # vi /tmp/test.sh
  2. #!/bin/bash
  3. echo Please enter your name
  4. read name
  5. echo My Name is $name
  6. # ./test.sh
  7. Please enter your name
  8. LinuxTechi
  9. My Name is LinuxTechi