I seem to recall from comments on this site that the contents of arithmetic expansion may be word split, but I can't find the comment again.
Consider the following code:
printf '%d\n' "$(($(sed -n '/my regex/{=;q;}' myfile)-1))"
If the sed
command outputs a multi-digit number and $IFS
contains digits, will the command substitution get word split before the arithmetic occurs?
(I've already tested using extra double quotes:
printf '%d\n' "$(("$(sed -n '/my regex/{=;q;}' myfile)"-1))"
and this doesn't work.)
Incidentally the example code above is a reduced-to-simplest-form alteration of this function that I just posted on Stack Overflow.
Best Answer
No, it doesn't.
In
$((expression))
, expression is treated as it was in double quote, as POSIX specified.But beware that the expression inside command substitution still be subjected to
split+glob
:With double quote:
Like other expansions, arithmetic expansion, if not inside double quote, undergo
split+glob
: