# 代表不解释不执行
–语法:#-比如:# 这是一行注释
#bash [-nvx] scripts.sh
–选项与参数:
-n :不要运行script,仅查询语法的问题;
-v :再运行sccript前,先将整个scripts 的内容输出到屏幕上;
-x :将执行到的script 内容显示到屏幕上,这是很有用的参数!
•创建一个脚本文件sh01.sh:
#!/bin/bash
echo "hello
mkdir./test/adirs./test/bdirs
ls-l ./
•以上内容中,我们制造一个bug:
–echo "hello 这里我们忽略最后的双引号
•#bash [-nvx] scripts.sh
–选项与参数:
-n :不要运行script,仅查询语法的问题;
- [root@hadoop scripts]# more hello.sh
- #!bin/bash
- echo "hello,world"
- [root@hadoop scripts]# hello.sh
- -bash: hello.sh: command not found
- [root@hadoop scripts]# bash hello.sh
- hello,world
使用选项-vx做进一步测试
•创建一个脚本文件test.sh:
#!/bin/bash
mkdir-p ./test/{a,b,c}dirs
scp/etc/{profile,init.d/network} ./test/
echo $PATH
#bash -vx test.sh
–-v选项使得脚本中的命令显示出来
–-x选项显示shell对脚本命令的解释结果,即shell解释器扩展命令字符串的结果
•扩展知识:
–shell扩展:花括号扩展
–shell扩展:变量参数扩展
•通过使用tree命令显示当前目录的属性结构
•*通过yum install tree -y来安装该命令
•shell扩展:花括号扩展
–mkdir -p ./test/{a,b,c}dirs
–+ mkdir -p ./test/adirs ./test/bdirs ./test/cdirs
–scp /etc/{profile,init.d/network} ./test/
–+ scp /etc/profile /etc/init.d/network ./test/
•花括号扩展:
–不能出现在引用中
–花括号前后的前缀是可选的
–最少出现一个逗号
•shell扩展:变量参数扩展
–echo $PATH
–+ echo /usr/lib64/qt-3.3/bin:/u。。。。。。
•符号$对使用的bash而言是获取参数变量值的特殊标识
–完整写法:${parameter}