How can I make a script to count up by fives?
Since you use brace expansion anyway, so make use of its feature fully:
echo {375..3500..5}
You can also use this technique to print each number in separate line with optional text by using printf
instead of echo
, for example:
$ printf "Number %s is generated.\n" {375..3500..5}
Number 375 is generated.
Number 380 is generated.
Number 385 is generated.
...
Edit
As pointed out by @kojiro in the comment Mac OS uses bash 3 as the default shell, which doesn't support increment in sequence expression of brace expansion. You need to upgrade to bash version 4 or use other shell which supports that (e.g. recent zsh).
Alternatively a traditional C-style for loop can be used:
for ((i=375; i<=3500; i+=5)); do
echo $i
done
This is perhaps less clear than using seq, but it doesn't spawn any subprocesses. Though since I'm familiar with C, I wouldn't have any difficulty understanding this, but YMMV.
Using SEQ(1)
for i in $(seq 375 5 3500)
do
echo $i
done
Or, simply:
seq 375 5 3500