Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

POSIX sh syntax for for-loops [SC2039]

The following command works well on my shell :

for ((j=0; j<=24; j++))
do > $j.json
done

but having the following notification :

SC2039 In POSIX sh, arithmetic for loops are undefined.

I was wondering what would be the equivalent in POSIX in order not to have interpeting issues on other systems.

like image 849
crocefisso Avatar asked Dec 23 '15 10:12

crocefisso


2 Answers

I guess the standards-compliant way of doing it would be something like this:

j=0
while [ $j -le 24 ]; do
    true > "$j.json"
    j=$(( j + 1 ))
done
like image 199
Tom Fenech Avatar answered Oct 04 '22 01:10

Tom Fenech


Another way that should work in a POSIX shell:

for j in `seq 0 24`; do
    ...
done
like image 22
Johannes Weiss Avatar answered Oct 03 '22 23:10

Johannes Weiss