标签:
一、Shell输入功能
[root@Salve four]# cat test.sh #!/bin/bash #-e 参数可以解析语句中的转义字符 echo -e "my name is user1\n my name is user2" #-n 参数可以让echo命令结尾不换行 echo -n "my name is user1\n my name is user2" echo #输出一个空行 #一个应用实例 echo -n "请输入你的名字:" read name echo $name echo "my name is $name" [root@Salve four]#./test.sh my name is user1 my name is user2 my name is user1\n my name is user2 请输入你的名字:tom tom
[root@Salve four]# cat demo.sh #!/bin/bash read -p ‘输入你的名字:‘ name echo $name [root@Salve four]#./demo.sh 输入你的名字:tom tom
[root@Salve four]# cat output.sh #!/bin/bash echo "Hello World!" echo -e "Hello World\nVery Good!" echo -e "\033[32;47m [test]\033[0m"
[root@Salve four]#./output.sh HelloWorld! HelloWorld VeryGood! [test]
[root@Salve four]# cat out2.sh #!/bin/bash echo -e "httpd process \033[32;40m [OK] \033[0m " [root@Salve four]# sh out2.sh httpd process [OK]
root@Salve four]# cat a.sh #!/bin/bash cat<<x #注意:可以是任意值,而非x,表示从x开始到x结束,原样输出 Please input your name: #heredoc字符串 1)user1 2)user2 3)user3 x [root@Salve four]# sh a.sh Please input your name: 1)user1 2)user2 3)user3
[root@Salve four]# sh a.sh | tee menu.txt Please input your name: 1)user1 2)user2 3)user3 [root@Salve four]# ls a.sh demo.sh menu.txt out2.sh output.sh test.sh
添加行号
[root@Salve four]# cat b.sh #!/bin/bash cat /etc/passwd | head -2|nl nl /etc/passwd | head -2 [root@Salve four]# sh b.sh 1 root:x:0:0:root:/root:/bin/bash 2 bin:x:1:1:bin:/bin:/sbin/nologin 1 root:x:0:0:root:/root:/bin/bash 2 bin:x:1:1:bin:/bin:/sbin/nologin
标签:
原文地址:http://www.cnblogs.com/chinas/p/5557753.html