syntax error at line 33: `elif` unexpected


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers syntax error at line 33: `elif` unexpected
# 1  
Old 02-09-2006
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?
# 2  
Old 02-09-2006
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

# 3  
Old 02-09-2006
Should there be a fi at the end of the last elif statement?

elif test $option = x
then
echo "bye"
fi
# 4  
Old 02-09-2006
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.
# 5  
Old 02-09-2006
i was missing then after the elif statement.

thanks for that. i read over it so many times and didnt see it
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Sh: -c: line 0: syntax error near unexpected token `(' how to resolve this

Below query is not working for me. Please help me on this DATA EXCLUDE STATEMENT: TABLE:\"LIKE \'%\_HISTORY\'\", TABLE:\"LIKE \'%\_HIST\'\", TABLE:\"in \(select tname from tab where REGEXP_LIKE(TNAME,\'\_H$\'\))\", TABLE:\"LIKE \'%\_LOG\'\", TABLE:\"LIKE \'DW\_%\'\", TABLE:\"LIKE... (1 Reply)
Discussion started by: princy
1 Replies

2. Shell Programming and Scripting

Syntax error at line 24: `(' unexpected

Hi, I am getting an wired error.... the script is running fine when i run it manually... but the same when i try to run in nohup mode, i am getting error if Error: syntax error at line 24: `(' unexpected The above if is the 24th line!!! I dont understand the error... (4 Replies)
Discussion started by: Nithz
4 Replies

3. Shell Programming and Scripting

Syntax error near unexpected token 'elif'

Solaris 10 This is my script: #!/bin/bash #Script to print number of users and print list of them NO=`awk < /etc/passwd -F: '{ print $1 }' | wc -l` echo There are $NO users on system. echo "Do you want me to list them? (y or n):" read YORN if ] awk < /etc/passwd -F: '{ print $1 }'... (5 Replies)
Discussion started by: kaustubh
5 Replies

4. Shell Programming and Scripting

Syntax error at line 14: `gw_user=' unexpected

Masters, i iam writing a script (dont have much experience in the process of learning) which handles file copy to multiple servers and users for deployment purpose. Below is the snippet. When ever i run i get syntax error but it works fine on another machine. Please help me out. if then... (10 Replies)
Discussion started by: ameyrk
10 Replies

5. Shell Programming and Scripting

syntax error near unexpected token `elif'

what is wrong with the below script: --------------------------------------------------------------------------------- #!/bin/bash echo "Setting JrePath..." grep -w "export JrePath" /etc/profile Export_Status=$? if echo "JrePath declared" elif echo "JrePath not declared" echo... (2 Replies)
Discussion started by: proactiveaditya
2 Replies

6. UNIX for Dummies Questions & Answers

syntax error at line 8: `(' unexpected

Hi I am having a shell script load_data.sh which calls /home/users/project/.profile. When am executing the script, am getting below error: $sh -x bin/load_data.sh null + . /home/users/project/.profile bin/load_data.sh: syntax error at line 8: `(' unexpected The line which is throwing... (1 Reply)
Discussion started by: brijesh.dixit
1 Replies

7. Shell Programming and Scripting

syntax error at line 28: `(' unexpected

hi can anyone pls look into this....shell script... Pls find the error below: > sh -n tmp tmp: syntax error at line 28: `(' unexpected isql -Usa -S$1 -P`grep $1 dbpassword|cut -d ":" -f3` -w2000 -b<<! set nocount on declare @i int declare @dbname char(6) declare @tmp int if... (10 Replies)
Discussion started by: rajashekar.y
10 Replies

8. UNIX Desktop Questions & Answers

line 3: syntax error near unexpected token `('

Hi All I've used UNIX in the past experimenting with commands through terminal but thats about it. Im now currently teaching myself "C". Using a book from the library, the first chapter asks you run and compile your program from a command-line prompt. As you will see the program is very simple,... (4 Replies)
Discussion started by: camzio
4 Replies

9. Shell Programming and Scripting

interface_file_ff.sh[99]: syntax error at line 1 : `)' unexpected

Hi, I tried to execute the following code but it showed the output mobile number : 35353425 corr plan id : 13-may-2008 corr target : 551 active_dt : 23414 no ident : IDD action name: A To get the subscriber number for the given mobile number and check if it is active and not... (1 Reply)
Discussion started by: geekforu
1 Replies

10. Programming

sh: syntax error at line 1: `>' unexpected

I compiled C program under SUN OS sparcv9 ...I had a problem related to SIGBUS which has been resolved by adding an option to the CC compiler which is memory alignement option ..-memalign=1i as I remmber ...after running the program I got the below error please let me KNow more details what should... (2 Replies)
Discussion started by: atiato
2 Replies
Login or Register to Ask a Question