My for loop is not working:
#!/bin/sh
for (( count=2; count < 5; count++))
do
parameter=$count
echo开发者_运维百科 $parameter
done
Error:
./new.sh: syntax error at line 2: `(' unexpected
The (( ))
construct is not POSIX. You must use an interpreter like #!/bin/bash
if you want this.
The POSIX alternative for this would be:
for count in 2 3 4; do
parameter=$count
echo $parameter
done
Or
for count in $(seq 2 4); do
parameter=$count
echo $parameter
done
The latter being more scalable at the cost of calling an external binary (seq
)
精彩评论