Quote:
Originally Posted by
Perderabo
… … …
Leaving off the $ is much faster and, provided that the variable only contains a simple scalar will give the same result.
Both
((expression)) and
$((expression)) perform an arithmetic evaluation of
expression. After evaluating
expression,
$((expression)) returns a string representing the resulting value.
((expression)) returns a 0 exit status if
expression evaluates to a non-zero value and 1 otherwise.
Other than the time taken to format the results, there shouldn't be any noticeable difference in speed between
((expression)) and
$((expression)).
Note that the standards require conforming shells to support arithmetic expansion (
$((expression))). The standards explicitly allow for the arithmetic evaluation command (
((expression))) to be provided, but do not currently require conforming shells to provide it. The standards also explicitly require applications that invoke nested subshells to separate the opening parentheses opening the subshell environments with one or more IFS characters to avoid an ambiguity in the grammar in shells that support the arithmetic evaluation command.