Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Brace expansion {1..10} in for loop is not portable #17

Open
gregory-nisbet opened this issue Apr 21, 2016 · 0 comments
Open

Brace expansion {1..10} in for loop is not portable #17

gregory-nisbet opened this issue Apr 21, 2016 · 0 comments

Comments

@gregory-nisbet
Copy link

Bash, even in posix emulation mode, will expand braced sequences (I don't think that's the official name for this construction).

$ bash --posix -c 'echo {1..10}'
1 2 3 4 5 6 7 8 9 10

But a more minimal shell like dash will not perform this expansion

$ dash -c 'echo {1..10}'
{1..10}

seq is pretty common on Linux, but is not itself POSIX. It isn't available on FreeBSD, for instance.

for i in `seq 1 10`; do
    echo "$i"
done

The POSIXest way I can think of to do this is to use a while loop and an explicit test.

i=1
while [ "$i" -le 10 ]; do
    echo "$i"
    i="$((i+1))"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant