- 论坛徽章:
- 0
|
原帖由 7717060 于 2008-7-11 08:16 发表 ![]()
() 在一子shell(sub-shell)中运行括号括起来的命令
(()) 在某个shell中对变量进行求值和赋值,并进行数学计算
$(()) 对括起来的表达式进行求值
[] 与test命令相同
[[]] 用于字符串比较
$() ...
[[ ]] 就是条件表达式,在bash中,字符串比较用 > < != == <= >= 只是在 [ ] 中 < >需要转义;对于数值比较,用 -lt -le -eq -ge -gt 来比较
man bash中有这些:
Command Substitution
Command substitution allows the output of a command to replace the command name. There are two forms:
$(command)
or
`command`
Bash performs the expansion by executing command and replacing the command substitution with the standard output of the command, with any trailing
newlines deleted. Embedded newlines are not deleted, but they may be removed during word splitting. The command substitution $(cat file) can be
replaced by the equivalent but faster $(< file).
When the old-style backquote form of substitution is used, backslash retains its literal meaning except when followed by $, `, or \. The first
backquote not preceded by a backslash terminates the command substitution. When using the $(command) form, all characters between the parentheses
make up the command; none are treated specially.
Command substitutions may be nested. To nest when using the backquoted form, escape the inner backquotes with backslashes.
If the substitution appears within double quotes, word splitting and pathname expansion are not performed on the results.
Arithmetic Expansion
Arithmetic expansion allows the evaluation of an arithmetic expression and the substitution of the result. The format for arithmetic expansion
is:
$((expression))
The old format $[expression] is deprecated and will be removed in upcoming versions of bash.
The expression is treated as if it were within double quotes, but a double quote inside the parentheses is not treated specially. All tokens in
the expression undergo parameter expansion, string expansion, command substitution, and quote removal. Arithmetic expansions may be nested.
The evaluation is performed according to the rules listed below under ARITHMETIC EVALUATION. If expression is invalid, bash prints a message
indicating failure and no substitution occurs.
Process Substitution
Process substitution is supported on systems that support named pipes (FIFOs) or the /dev/fd method of naming open files. It takes the form of
<(list) or >(list). The process list is run with its input or output connected to a FIFO or some file in /dev/fd. The name of this file is
passed as an argument to the current command as the result of the expansion. If the >(list) form is used, writing to the file will provide input
for list. If the <(list) form is used, the file passed as an argument should be read to obtain the output of list.
When available, process substitution is performed simultaneously with parameter and variable expansion, command substitution, and arithmetic
expansion. |
|