The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
awk Shell Script error : "Syntax Error : `Split' unexpected Herry UNIX for Dummies Questions & Answers 2 03-17-2008 08:16 AM
"syntax error at line 21 :'done' unexpected." error message" ibroxy Shell Programming and Scripting 3 08-08-2007 03:45 AM
syntax error at line 59: `end of file' unexpected Remi SUN Solaris 4 01-16-2007 11:48 AM
for loop not working - syntax error at line 6: `end of file' unexpected debojyoty Shell Programming and Scripting 2 03-10-2006 12:45 PM
sh: syntax error at line 1: `>' unexpected atiato High Level Programming 2 03-16-2004 04:39 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 02-09-2006
Registered User
 

Join Date: Feb 2006
Posts: 2
syntax error at line 33: `elif` unexpected

Code:
#!/bin/sh

echo "Choose option: e, d, l, t, p, or x."
read option

if test $option = e

then

        echo "Filename?"
        read file

        if test ! -f $file
        then
                echo "No such file"
        else
                echo "Yes its a file"
        fi

elif test $option = d

        echo "Directory?"
        read dir

        if test ! -d $dir
        then
                echo "no such dir"
        else
                echo "yes its a dir"

        fi

elif test $option = l

then

        ls

elif test $option = t

then

        date

elif test $option = p

then

        echo "Make file readable to all"
        read filep

        if test $filep ! -f $file
        then
                echo "no file exists"
        else
                chmod 777 $file
        fi

elif test $option = x
then
        echo "bye"
"menuscript" 74 lines, 647 characters

syntax error at line 33: `elif` unexpected



Any ideas?
Reply With Quote
Forum Sponsor
  #2  
Old 02-09-2006
Registered User
 

Join Date: Jan 2005
Posts: 682
Where do you begin; there are so many things wrong.
  1. Read the man pages for "test"
  2. Learn the basic structure of if then elif else fi statement
  3. Narrow your scope so that you can understand a simple control structure like if
For starters, try something like this:
Code:
if [ $option == e ]
then
   ... do something ...
elif [ $option == d ]
then
   ... do something ...
else
   ... do something else ..
fi
Reply With Quote
  #3  
Old 02-09-2006
Registered User
 

Join Date: Jan 2006
Posts: 51
Should there be a fi at the end of the last elif statement?

elif test $option = x
then
echo "bye"
fi
Reply With Quote
  #4  
Old 02-09-2006
Registered User
 

Join Date: Jan 2005
Posts: 682
Yes, and there should be a "then" after "elif test $option = d".

Since the OP is trying to lear the constructs, it's much better to start small and add more.
Reply With Quote
  #5  
Old 02-09-2006
Registered User
 

Join Date: Feb 2006
Posts: 2
i was missing then after the elif statement.

thanks for that. i read over it so many times and didnt see it
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 10:59 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0