bash loop problem - output not as expected (returned command)

32 views Asked by At

I have a script.sh

#!/bin/bash
for i in {1..$1}
do
    echo $i
done

someone could explain me why if I try ./script.sh 10 my output is {1..10}? expected 1 2 ... 10

1

There are 1 answers

1
Scott On

You're echoing the parameter that you're passing in instead of printing out the loop iteration. Try:

echo $i