shell脚本执行方式

一 echo输出命令
echo [选项] [输出内容]
选项:
-e:支持反斜杠控制的字符转换
 
二 控制字符


 
 
三 输出颜色


 
 
四 Xshell设置字符格式方法
选当前会话,然后按照下图操作


 
 
五 脚本执行
1 赋予执行权限,直接运行
chmod 755 hello.sh
./hello.sh
2、通过Bash调用执行脚本
bash hello.sh
 
六 实战
[root@localhost ~]# echo "bls and cangls"
bls and cangls
[root@localhost ~]# echo -e "bls and\b cangls"
bls an cangls
[root@localhost ~]# echo -e "hello"
hello
[root@localhost ~]# echo -e "hel\blo"
helo
[root@localhost ~]# echo -e "h\te\tl\nl\to\t"
h e l
l o
[root@localhost ~]# echo -e "\x68\t\x65\t\x6c\n\x6c\t\x6f\t"
h e l
l o
[root@localhost ~]# echo "嫁人就要嫁凤姐"
嫁人就要嫁凤姐
[root@localhost ~]# echo -e "\e[1;31m嫁人就要嫁凤姐\e[0m"
嫁人就要嫁凤姐
[root@localhost ~]# echo -e "\e[1;35m嫁人就要嫁凤姐\e[0m"
嫁人就要嫁凤姐
[root@localhost ~]# echo -e "\e[1;32m嫁人就要嫁凤姐\e[0m"
嫁人就要嫁凤姐
[root@localhost ~]# echo -e "\e[1;33m嫁人就要嫁凤姐\e[0m"
[root@localhost ~]# vim hello.shell
[root@localhost ~]# .\hello.shell
[root@localhost ~]# chmod 755 hello.shell
[root@localhost ~]# ./hello.shell
天上掉下个林妹妹
[root@localhost ~]# bash hello.shell
天上掉下个林妹妹

猜你喜欢

转载自cakin24.iteye.com/blog/2391629