Next: , Previous: , Up: Portable Shell   [Contents][Index]


11.10 Parentheses in Shell Scripts

Beware of two opening parentheses in a row, as many shell implementations treat them specially, and Posix says that a portable script cannot use ‘((’ outside the ‘$((’ form used for shell arithmetic. In traditional shells, ‘((cat))’ behaves like ‘(cat)’; but many shells, including Bash and the Korn shell, treat ‘((cat))’ as an arithmetic expression equivalent to ‘let "cat"’, and may or may not report an error when they detect that ‘cat’ is not a number. As another example, ‘pdksh’ 5.2.14 does not treat the following code as a traditional shell would:

if ((true) || false); then
  echo ok
fi

To work around this problem, insert a space between the two opening parentheses. There is a similar problem and workaround with ‘$((’; see Shell Substitutions.