Link to home
Start Free TrialLog in
Avatar of digs developer
digs developer

asked on

Need simple example of loop in unix shell script

Need simple example of loop in unix shell script
Avatar of Brian Utterback
Brian Utterback
Flag of United States of America image

Which shell? What kind of loop?

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
While loop....

i=1
while [ "$i" -lt "100" ]; do
      echo $i
      let "i=i+1"
      sleep 1
done
Avatar of Tintin
Tintin

Loop to read a file

while read line
do
   echo "$line"
done <filename

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Gerwin Jansen
Gerwin Jansen
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial