Answers:
该$(( … ))
语法是算术表达式。
缺少$(
和之间的空格(
,以避免算术表达式语法。
实际上,shell命令语言规范中有关命令替换的部分对此进行了警告:
If the command substitution consists of a single subshell, such as:
$( (command) )
a conforming application shall separate the "`$(`" and '`(`' into two tokens
(that is, separate them with white space). This is required to avoid any
ambiguities with arithmetic expansion.
尝试
export X="$(echo "abc"; echo "def")"
ksh
并且bash
是唯一的例外)。
`...`
,$(...)
无论如何都要启动一个子shell,所以(...)
不需要内部(浪费一个进程)。例如,您将需要空间$( (...); (...) )
(可能需要内部子外壳)。