标签:
read 命令从标准输入中读取一行,并把输入行的每个字段的值指定给 shell 变量
read 后面接的参数可以一个,也可以多个
[root@Director ~]# read -p "Please input two number: " n1 n2 #注意空格 Please input two number: 9 8 [root@Director ~]# echo $n1,$n2 9,8
AIX机器上是不支持-p的,这个时候可以用echo -n进行替代
[root@Director ~]# echo -n "Please input two number:";read n1 n2 Please input two number:1 2 [root@Director ~]# echo $n1,$n2 1,2
[root@Director ~]# read -n3 -p "Please input a number: " var1 Please input a number: 123[root@Director ~]#
[root@Director test]# cat demo.sh #/bin/bash if read -t 5 -p "Please input your anwser: " anwser then echo $anwser else echo -e "\nsorry,timeout" fi [root@Director test]# sh demo.sh Please input your anwser: sorry,timeout
[root@Director test]# read -s -p "Pleas input your password: " p Pleas input your password: [root@Director test]# echo $p 12345
生产应用,根据端口号杀进程
lsof -i :8080 |awk ‘{print $2}‘|while read pid do if [ "${pid}" != "PID" ];then kill -9 $pid break fi done
标签:
原文地址:http://www.cnblogs.com/zydev/p/5746742.html