While loop error: Unexpected token done


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting While loop error: Unexpected token done
# 1  
Old 03-25-2009
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:

Code:
#!/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.

Last edited by vgersh99; 03-25-2009 at 04:58 PM..
# 2  
Old 03-25-2009
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.

Last edited by vgersh99; 03-25-2009 at 05:14 PM..
# 3  
Old 03-25-2009
Looks like you've got an if statement without corresponding fi
# 4  
Old 04-13-2009
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?
# 5  
Old 04-13-2009
while read line; do
..
if [[$line = *sometext*]]; then
# 6  
Old 04-13-2009
Hi erenay,
i think you forgot a thousand of (") and(Smilie 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
# 7  
Old 04-13-2009
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)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Syntax error near unexpected token 'do'

Hello all, Please i have this command i used to zip different files in differents directory, but i have an error. Note that when i run the command in one directory it works fine. /X5/WORK/BGH/INV/REG/pdf/SEND/BGH12523/1/*.fo /X5/WORK/BGH/INV/REG/pdf/SEND/BGH24523/1/*.fo... (3 Replies)
Discussion started by: gillesi
3 Replies

2. Shell Programming and Scripting

Syntax error near unexpected token `else'

Hello every one!! I don't know where I am going wrong but I am finding it difficult to clear this error of syntax error near unexpected token `else' I am writing a simple shell script to find a file in a directory and if found execute that else return an error to the log file ... (14 Replies)
Discussion started by: masubram
14 Replies

3. Shell Programming and Scripting

For loop - unexpected token `do

My requirement is to search for current date-1 .log files in /usr/sas/sas_config/Lev1/SASApp/StoredProcessServer/Logs folder and write the file name to filenames.txt When I ran the script below, I got error as syntax error near unexpected token `do I'm not sure what is wrong in my code. I... (11 Replies)
Discussion started by: Ram Kumar_BE
11 Replies

4. Shell Programming and Scripting

Syntax error near unexpected token `else'

Hi, I am trying to read the session log through script. But it keeps showing me some error near. I have tried everything. Even tried converting the script using sed command to remove the hidden characters(\r).But nothing seems to be working.Below is the script : #!/bin/bash cd... (6 Replies)
Discussion started by: Aryan12345
6 Replies

5. Shell Programming and Scripting

Syntax error near unexpected token `('

What do I do here? #!/bin/bash payload=-1 AND 1=IF(21,BENCHMARK(5000000,MD5(CHAR(115,113,108,109,97,112))),0)# hash=`echo -n $payload md5sum tr -d 'n' sed 'ss-sg' md5sum tr -d 'n' sed 'ss-sg'` curl --data cs2=chronopay&cs1=$payload&cs3=$hash&transaction_type=rebill... (2 Replies)
Discussion started by: iiiiiiiiiii
2 Replies

6. Shell Programming and Scripting

syntax error near unexpected token `='

Hi all, This is a script which converts hex to bin. However am finding an error while executing syntax error near unexpected token `=' `($hexfile, $binfile) = @ARGV;' I am running using ./fil.pl <hexfile> <binfile> ################################################### # # this script... (3 Replies)
Discussion started by: jaango123
3 Replies

7. UNIX for Dummies Questions & Answers

Syntax error near unexpected token

hi! just want to seek help on this error: syntax error near unexpected token 'do this is my script # !/bin/sh # for y in 27 25 do exemmlmx -c "ZEEI;" -n XRT$y >> blah done what can be wrong? thanks! (6 Replies)
Discussion started by: engr.jay
6 Replies

8. Shell Programming and Scripting

Unexpected Token Error `;;'

Hello all, Im having an Issue with my script for switch statement , can someone let me know where do i need to correct it. 7 ##******************************************************************************************************* 8 ## ********** FUNCTION USAGE *********** ... (13 Replies)
Discussion started by: raghunsi
13 Replies

9. Shell Programming and Scripting

Syntax error near unexpected token `done'

Hi all, Here is a simple script that is working in one server and is giving a syntax error in other server. Can somebody help me ? #!/bin/bash # ftp files done < $file errors: I tried..with no success: if ; then (21 Replies)
Discussion started by: Lenora2009
21 Replies

10. Shell Programming and Scripting

Syntax error near unexpected token `('

Guys , This is an output of my script errored out for "Syntax error near unexpected token `(' " Can someone tell me whats wrong with my script. Below is my original script pasted. #!/bin/bash Script Creation Date 01/21/2010 Author baraghun ... (7 Replies)
Discussion started by: raghunsi
7 Replies
Login or Register to Ask a Question