I want to write a loop in Bourne shell which iterates a specific set of numbers. Normally I would use seq
:
for i in `seq 1 10 15 20`
#do stuff
loop
But seemingly on this Solaris box seq
does not exist. Can anyone help by providing another solution to iterating a list of numbers?
The Bourne shell is used for scripting. It provides command-based programming to interpret and execute user commands. As a user types a command, the shell interprets it so the operating system can take action, such as automating a task. The Bourne shell was the default shell for Unix version 7.
seq command in Linux is used to generate numbers from FIRST to LAST in steps of INCREMENT. It is a very useful command where we had to generate list of numbers in while, for, until loop.
The "shbang" line is the very first line of the script and lets the kernel know what shell will be interpreting the lines in the script. The shbang line consists of a #! followed by the full pathname to the shell, and can be followed by options to control the behavior of the shell.
The Bourne shell is an interactive command interpreter and command programming language. The bsh command runs the Bourne shell. The Bourne shell can be run either as a login shell or as a subshell under the login shell. Only the login command can call the Bourne shell as a login shell.
try
for i in 1 10 15 20
do
echo "do something with $i"
done
else if you have recent Solaris, there is bash 3 at least. for example this give range from 1 to 10 and 15 to 20
for i in {1..10} {15..20}
do
echo "$i"
done
OR use tool like nawk
for i in `nawk 'BEGIN{ for(i=1;i<=10;i++) print i}'`
do
echo $i
done
OR even the while loop
while [ "$s" -lt 10 ]; do s=`echo $s+1|bc`; echo $s; done
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With