怎么让shell脚本获得来自终端输入和创建新终端例子详解。
read命令可以读取来自终端(使用键盘)的数据。read命令得到用户的输入并置于你给出的变量中。例如:
# vi /tmp/test.sh #!/bin/bash echo ‘Please enter your name' read name echo “My Name is $name” # ./test.sh Please enter your name LinuxTechi My Name is LinuxTechi
Linux下在Shell脚本中创建新终端:
gnome-terminal -t "title-name" -x bash -c "sh ./run.sh;exec bash;"
-t 为打开终端的标题,便于区分。
-x 后面的为要在打开的终端中执行的脚本,根据需要自己修改就行了。
最后的exec bash;是让打开的终端在执行完脚本后不关闭。