The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
for loop not working - syntax error at line 6: `end of file' unexpected debojyoty Shell Programming and Scripting 3 04-13-2009 10:31 AM
line 3: syntax error near unexpected token `(' camzio UNIX Desktop for Dummies Questions & Answers 4 09-29-2008 11:10 AM
"syntax error near unexpected token `fi' " GIC1986 SUN Solaris 4 09-19-2008 01:17 PM
awk Shell Script error : "Syntax Error : `Split' unexpected Herry UNIX for Dummies Questions & Answers 2 03-17-2008 11:16 AM
syntax error near unexpected token...what caused? joshuaduan Shell Programming and Scripting 8 05-14-2007 10:02 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-25-2009
warlock129 warlock129 is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 38
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 03:58 PM..
  #2 (permalink)  
Old 03-25-2009
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131
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 04:14 PM..
  #3 (permalink)  
Old 03-25-2009
mjd_tech mjd_tech is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 12
Looks like you've got an if statement without corresponding fi
  #4 (permalink)  
Old 04-13-2009
erenay erenay is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 2
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 (permalink)  
Old 04-13-2009
giannicello giannicello is offline
Registered User
  
 

Join Date: Sep 2001
Location: Phoenix
Posts: 169
while read line; do
..
if [[$line = *sometext*]]; then
  #6 (permalink)  
Old 04-13-2009
giannicello giannicello is offline
Registered User
  
 

Join Date: Sep 2001
Location: Phoenix
Posts: 169
if [[ $line = *sometext* ]]; then

Missed the blanks around the [[ ]]...you can figure out the other stuff.
  #7 (permalink)  
Old 04-13-2009
sauron's Avatar
sauron sauron is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 33
Hi erenay,
i think you forgot a thousand of (") and( 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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:46 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0