Atomiklan
Atomiklan

Reputation: 5454

sh shell for loop without seq

I'm writing a script that must work in bash and sh and it runs on a miniscule platform and some things appear to be missing such as seq. All these limitations/requirements is making writing this script VERY difficult. I need to write a for loop that works under all these requirements.

This only works for bash:

for (( i = 0; i <= 4; i++ ))
do
  echo $i
done

This should work in sh, but the platform I'm using is apparently missing seq.

for i in $(seq 1 $INPUT); do

$INPUT is the max defined by the user.

Upvotes: 3

Views: 1494

Answers (1)

Sammitch
Sammitch

Reputation: 32272

Kids these days are so spoiled with their newfangled shell builtins.

i=1
while [ $i -le $INPUT ]; do
  echo $i
  i=$(expr $i + 1)
done

Upvotes: 16

Related Questions