【`】`command`结构可以将命令的输出赋值到一个变量中去.
e.g
[root@monitor test]# cat ceshi.sh
#!/bin/bash
echo The time is :"`date`"!
[root@monitor test]# ./ceshi.sh
The time is :Mon Feb 21 10:23:18 CST 2011!
注:这里也在此说明了【"】不对反引号【`】起屏蔽作用
【!】
取反操作符[叹号, 即!]
e.g
!=表示不等于
【*】
通用匹配符号;或者表示乘号(运算)
【$】
变量替换
e.g
dir=/root
echo $dir
/root
【$1】
额外需要输入的参数
用以添加额外参数
[root@monitor test]# echo "/root/shell">>dirfile
[root@monitor test]# ./ls.sh dirfile
The number of files in /root/shell is 2
[root@monitor test]# cat ls.sh
#!/bin/bash
dir=$(cat /root/test/$1)
echo "The number of files in $dir is `ls $dir|wc -l`"
exit 0
【{}】
代码块[大括号, 即{}]. 又被称为内部组, 这个结构事实上创建了一个匿名函数(一个没有名字的函数). 然而, 与"标准"函数
不同的是, 在其中声明的变量,对于脚本其他部分的代码来说还是可见的.
【>】
重定向替换
【>>】
追加
【|】
管道符
ls |wc -l
【&】
后台运行命令. 一个命令后边跟一个& 表示在后台运行.
e.g
ls /root
sleep 10
pwd
【%】
取模.
e.g
date +%Y%m%d
【^】
行首. 在正则表达式中, "^"表示定位到文本行的行首.