01
start
开始
![e5d97ba02b96a14037e6e9110337684d.png](https://i-blog.csdnimg.cn/blog_migrate/d7e73d0e0261ff2c5370a070494a95ea.png)
写法一:
#!/bin/bash
。
#!
位于解释器路径之前,
/bin/bash
是Bash的解释器命令路径。
![e5d97ba02b96a14037e6e9110337684d.png](https://i-blog.csdnimg.cn/blog_migrate/d7e73d0e0261ff2c5370a070494a95ea.png)
![e5d97ba02b96a14037e6e9110337684d.png](https://i-blog.csdnimg.cn/blog_migrate/d7e73d0e0261ff2c5370a070494a95ea.png)
写法二:
#!/bin/bash -ex
。
-e
,类似于在第二行写set -e
其意义是Exit immediately if a command exits with a non-zero status.
;
-x
的意思是Print commands and their arguments as they are executed
![e5d97ba02b96a14037e6e9110337684d.png](https://i-blog.csdnimg.cn/blog_migrate/d7e73d0e0261ff2c5370a070494a95ea.png)
02
frontend printing
终端打印
$ name=dou; echo -e "my name is\t$name"
my name is dou
如果需要在不同的命令之间输出一些信息给用户进行提示,在编写脚本时,输出不一样的颜色或者背景会比较醒目。
打印彩色字体 echo -e "\e[1;32m This is green text \e[0m"
打印彩色背景 echo -e "\e[1;42m This is green text \e[0m"
![ef43f50282eb8430f9b2b7f84fa973d7.png](https://i-blog.csdnimg.cn/blog_migrate/68ff3ec81c45af37666dc9044259ba54.png)
举例:
$ printf "%-5s %-10s %-4.2f\n" 1 Sarath 80.3456
1 Sarath 80.35
%s、%c、%d和%f都是格式替换符,