Is this an intended behaviour?
% cat sum.sh
sum=0
while read n; do
sum=$((sum+n))
done
echo $sum
% seq 10 | bash sum.sh
55
% yes ++sum | head -10 | bash sum.sh
1023
% echo 'x[$(echo Hello, world!>&2)]' | bash sum.sh
Hello, world!
0
% bash -c 'echo $BASH_VERSION'
5.0.9(0)-release
On 9/5/19 4:40 AM, YAMAGUCHI Takanori wrote:
> Is this an intended behaviour?
The command substitution in the evaluation of the array index? Yes,
array indices undergo word expansions.
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hi
I meant that the evaluation is unsafe. If this behaviour is
the defined feature, manpage should be added the warning that
"must not use unchecked input in an arithmetic expression context".
On 2019/09/05 23:08, Chet Ramey wrote:
> On 9/5/19 4:40 AM, YAMAGUCHI Takanori wrote:
>> Is this an intended