If you are die hard Bourne Shell (/bin/sh) scripter, it can be a challenge not to be enticed by the syntax niceties of the Born Again Borne Shell (/bin/bash).
One example is the `{..} syntax</code for simple for loops.
#!/bin/bash for I in {0..5} do echo $I done
0 1 2 3 4 5
This syntax is not valid in NOTE: However apparently it does work in Mac OS X, which is derived from BSD, not Linux. Note: Passing a string does not work by default. The approach to product the same result requires some format management. You can use You can use one of several other shell commands, in this example Or, the function specifically design for sequences of numbers And for these few examples, there will be more possibilities to achieve close to feature parity of the /bin/sh` on Linux.
#!/bin/sh
for I in {0..5}
do
echo $I
done
{0..5}
/bin/sh
gives you a for loop but it requires the full list of iterated values instead of a range.#!/bin/sh
for I in 0 1 2 3 4 5
do
echo $I
done
#!/bin/sh
for I in "0 1 2 3 4 5"
do
echo $I
done
#!/bin/sh
OIFS=$IFS
IFS=" "
for I in `echo "0 1 2 3 4 5"`
do
echo $I
done
IFS=$OIFS
while
#!/bin/sh
I=0
while [ $I -le 5 ]
do
echo $I
I=`expr $I + 1`
done
awk
#!/bin/sh
for I in `awk 'BEGIN{for (i=0;i<=5;i++) print i}'`
do
echo $I
done
seq
#!/bin/sh
for I in `seq 0 5`
do
echo $I
done
/bin/bash
syntax.
An example found on BSD is jot - 0 5
. This is not available Ubuntu by default but installed with the athena-jot
package. However the syntax is then different for correct usage.