digs developer
asked on
Need simple example of loop in unix shell script
Need simple example of loop in unix shell script
While loop....
i=1
while [ "$i" -lt "100" ]; do
echo $i
let "i=i+1"
sleep 1
done
i=1
while [ "$i" -lt "100" ]; do
echo $i
let "i=i+1"
sleep 1
done
Loop to read a file
while read line
do
echo "$line"
done <filename
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Here are some examples:
#!/bin/sh
for i in 1 2 3 4 5
do
echo "Looping ... number $i"
done
#!/bin/sh
for i in hello 1 * 2 goodbye
do
echo "Looping ... i is set to $i"
done
#!/bin/sh
INPUT_STRING=hello
while [ "$INPUT_STRING" != "bye" ]
do
echo "Please type something in (bye to quit)"
read INPUT_STRING
echo "You typed: $INPUT_STRING"
done