While loop error: Unexpected token done

I have tried to implement a while loop into the code but upon running the following code i am getting the errors:

./Assigntest: line 42: syntax error near unexpected token `done'
./Assigntest: line 42: `done'

The code is as follows:

#!/bin/bash
#Filename: Assignment Author: Luke Francis
quit=n
while [ "$quit" = "n" ]
do
clear
echo "OPERATOR ADMINISTRATIVE TOOL"
echo "Please enter your password:"
read password
if [ $password -eq 0600519 ]
then
clear
echo "1. User Information"
echo "2. Network Connectivity"
echo "3. Processes"
echo "4. System Information"
echo "5. Hardware Utilization"
echo "Which option do you require?"
read menunumber
case $menunumber in
1) echo "USER INFORMATION"
echo "1. Registered Users"
echo "2. Disk Usage"
echo "3. Last Logins"
echo "Q.Quit"
echo "Which option do you require?"
read menunumber2
case $menunumber2 in
1) awk -F: '{print $1}' /etc/passwd
echo "Hit the Enter Key to continue"
read junk;;
2) du
echo "Hit Enter Key to continue"
read junk;;
3) who
echo "Hit Enter Key to continue"
read junk;;
Q|q) quit=y;;
*) echo "INCORRECT PASSWORD"
"Assigntest" 43L, 925C written                                
lf1ect@star-gateway$ <0> ./Assigntest
./Assigntest: line 42: syntax error near unexpected token `done'
./Assigntest: line 42: `done'
lf1ect@star-gateway$ <2> vi Assigntest
read password
if [ $password -eq 0600519 ]
then
clear
echo "1. User Information"
echo "2. Network Connectivity"
echo "3. Processes"
echo "4. System Information"
echo "5. Hardware Utilization"
echo "Which option do you require?"
read menunumber
case $menunumber in
1) echo "USER INFORMATION"
echo "1. Registered Users"
echo "2. Disk Usage"
echo "3. Last Logins"
echo "Q.Quit"
echo "Which option do you require?"
read menunumber2
case $menunumber2 in
1) awk -F: '{print $1}' /etc/passwd
echo "Hit the Enter Key to continue"
read junk;;
2) du
echo "Hit Enter Key to continue"
read junk;;
3) who
echo "Hit Enter Key to continue"
read junk;;
Q|q) quit=y;;
*) echo "INCORRECT PASSWORD"
sleep 1
esac
done
echo "Thank you for using the Operator Administrative Tool."

To me the done statement looks to be correct but obviuosly there is something wrong i'd be grateful for some help.

you have embedded 'case'-s, but only one 'esac'.
Also next time use BB Codes when posting data/code samples - you'll increase the chances of your posts being answered - this is absolutely impossible to read/comprehend.

You have posted a part of a script from 'vi' and then the execution. This is impossible to read.
Post the entire script using BB Codes in one block AND then output you're getting. Maybe some good Samaritan will try to help you.
Good luck.

Looks like you've got an if statement without corresponding fi

Hi all,

I have a similar problem.
My script is like:

#!/bin/sh
FILENAME=$1
while read line do
if [[$line = *sometext*]] then echo $line fi
done < $FILENAME

And I get the error:

line 5: syntax error near unexpected token `done'
line 5: `done < $FILENAME

Would you please share any ideas about how to solve the problem?

while read line; do
..
if [[$line = *sometext*]]; then

Hi erenay,
i think you forgot a thousand of (") and(:wink: and spaces:

while read line do
if [[$line = *sometext*]] then echo $line fi
done < $FILENAME

must be:

while read line; do
if<space>[[<space>$line = *sometext*<space>]]; then echo "$line"; fi
done < $FILENAME

Bye

corrected script is here:

#!/bin/bash
#Filename: Assignment Author: Luke Francis
quit=n
while [ "$quit" = "n" ]
do
clear
echo "OPERATOR ADMINISTRATIVE TOOL"
echo "Please enter your password:"
read password
if [ $password -eq 0600519 ]
then
clear
echo "1. User Information"
echo "2. Network Connectivity"
echo "3. Processes"
echo "4. System Information"
echo "5. Hardware Utilization"
echo "Which option do you require?"
read menunumber
case $menunumber in
1) echo "USER INFORMATION"
echo "1. Registered Users"
echo "2. Disk Usage"
echo "3. Last Logins"
echo "Q.Quit"
echo "Which option do you require?"
read menunumber2
case $menunumber2 in
1) awk -F: '{print $1}' /etc/passwd
echo "Hit the Enter Key to continue"
read junk;;
2) du
echo "Hit Enter Key to continue"
read junk;;
3) who
echo "Hit Enter Key to continue"
read junk;;
Q|q) quit=y;;
*) echo "INCORRECT PASSWORD"
sleep 1
esac
esac #I added
fi #I added
done
echo "Thank you for using the Operator Administrative Tool."

You missed to close case and if statements (see mark I added)

if [[ $line = *sometext* ]]; then

Missed the blanks around the [[ ]]...you can figure out the other stuff.

Thanks a lot sauron and giannicello. As you can see I'm a newbie.
I tried

#!/bin/sh
FILENAME=$1
while read line; do
if [[ $line = *sometext* ]]; then echo "$line"; fi
done < $FILENAME

and I still get the error:

line 5: syntax error near unexpected token `done'
line 5: `done < $FILENAME

I'll continue playing with it and update here if I can fix it. Thanks

Ohh my...
I was using cygwin and I used d2u for my txt file but not for my sh file. I thought it was OK since I was using vim to edit it. After using d2u for the .sh file too, it worked correctly.
Thanks again for the quick answers, I liked this community very much!

don't think Bourne shell likes the [[.

try this:

#!/bin/ksh

FILENAME=$1

if [ ! -f "$FILENAME" ]; then
  echo usage: $0 file_name
  exit 1
fi

while read line; do

  if [[ $line = *sometext* ]]; then
    echo "$line"
  fi

done < $FILENAME