how to use while

I was trying to use while loop
and try to read it from text file and was not able to do it.

db.txt while read db
do
if [ "$1" = "dev"] then
script
else
echo"message"
fi
done

i am getting the error message.

I believe that you need something after "while".

while true
read etc...

or

while x=3
read etc....

db.txt while true read db
do
if [ "$1" = "dev"] then
script
else
echo"message"
fi
done

:cool:

they syntax for a while loop is as followes for the ksh shell.

while [ <condition> ]; do
<some stuff....>
<some cool stuff....>
<some awsome cool stuff....>
done

Gotta love the awesome cool stuff :wink:

What error are you getting?
Just by looking at what you posted, you might try:

cat db.txt | while read db something_else; do
 if [ $db = "expected" ]; then
    echo "$something_else"
 else
    echo "Nope"
 fi
done

This won't work with all shells, though. Most likely, it will work with ksh and zsh, but not sh or bash. Also, you can remove the "cat" at the beginning, and redirect the file into done:

 
[...]
done < db.txt

Thanks cat worked like charm.