On Tue, Dec 27, 2011 at 11:12:31PM +0800, lina wrote:
#!/bin/sh
for i in {1..10} ; do
Brace expansion is a bash feature, not a /bin/sh feature. When you put
#!/bin/sh at the top of your script, you are telling the operating system
to use /bin/sh as the interpreter when you run the script. And /bin/sh
won't understand brace expansions.
If you wish to use bash features in your scripts, you must use
#!/bin/bash
or
#!/usr/bin/env bash
as your shebang. This will make the operating system run bash to interpret
your script.
BTW, on script I used to use for i in $(seq 10)
just recent trying to learn more, so do some practice.
seq(1) is Linux-only. Some other OSes have jot(1) instead, but both of
those are nonstandard (and they have incompatible syntax).
The correct way to count to 10 in /bin/sh is:
i=1
while [ $i -le 10 ]; do
...
i=$((i+1))
done