+ 5

Why this source code only display odd natural numbers in Bash scripting?

Why this source code only display odd natural numbers in Bash scripting? for x in {1..99..2}; do echo $x; done there's no modulus syntax.

18th Aug 2019, 7:31 AM
Adi Pratama
Adi Pratama - avatar
3 Respostas
+ 3
in python : for x in (1:99:2): print x means (start : end : step) step means the amount of icrecement you can say...ex (1:99:2) will go 1 3 5 7 9 etc if (1:99:3) it will go like this: 1 4 7 10 13 etc.. and so on....
18th Aug 2019, 6:40 PM
Creed Deskenth
Creed Deskenth - avatar
+ 4
I guess the '2' says how to count in this numberseries. So it will be the distance, e.g. 1,3,5... Try {1..99..1} to get every natural number between 1 and 99. :)
18th Aug 2019, 7:44 AM
Tom Hammerbacher
Tom Hammerbacher - avatar
+ 2
it is like following in js. for (var i = 1; i <= 99; i+=2) { document.write(i); }
2nd Sep 2019, 4:21 PM
\•/
\•/ - avatar