-
Notifications
You must be signed in to change notification settings - Fork 1.8k
SC2257
Rafael Cepeda edited this page Jul 18, 2020
·
2 revisions
curl "$URL" > "image$((i++)).jpg"
i=$((i+1))
curl "$URL" > "image$i.jpg"
You are using an arithmetic expression that modifies a variable, e.g. $((x+=1))
or $((x++))
, in the name of a file to redirect from/to, in a here document, or in a here string.
The scope of these modifications depends on whether the command itself will fork:
echo foo > $((var++)).txt # Updates in BusyBox and Bash
cat foo > $((var++)).txt # Updates in Busybox, not in Bash
gcc foo > $((var++)).txt # Does not update in either
gcc() { /opt/usr/bin/gcc "$@"; }
gcc foo > $((var++)).txt # Now suddenly updates in both
Rather than rely on knowing which commands do and don't fork, or are and aren't overridden, simply do the updates in a separate command as in the correct code.
If you know your variable is scoped the way you want it, you can ignore this warning.
- Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc!
- https://stackoverflow.com/questions/62783161/arithmetic-expression-in-redirection/62964890#62964890