特殊符号
$()和`` 命令代换
替换为命令输出(输出到stdout的内容),
所有的shell支持使用反引号的方式进行命令替换,
命令替换可以嵌套,需要注意的是如果使用反引号的形式,在内部反引用前必须使用反斜杠转义
Current_Folder=$(cd `dirname $0`; pwd)
$ nproc
1
$ make -j $(nproc) #即make -j 1
$ echo $(date) #即echo 2021年 11月 04日 星期四 21:41:54 CST
2021年 11月 04日 星期四 21:41:54 CST
$ date
2021年 11月 04日 星期四 21:41:56 CST
$(()) 算术代换
匹配符 | 说明 |
---|---|
$(()) | 例如 echo $((4 + 6)) |
特殊变量
$#
expands to the number of arguments (positional parameters) i.e. $1, $2 ...
passed to the script in question or the shell in case of argument directly passed to the shell e.g. in bash -c '...' ....
.
$1, $2 …
arguments (positional parameters) passed to the script in question or the shell in case of argument directly passed to the shell e.g. in bash -c '...' ....
.
$0, $1, $2 …就是对应给shell的命令,以whitespace分隔,
所以$1, $2 … argument, $0 exe name