shell scripting error


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting shell scripting error
# 1  
Old 03-29-2009
shell scripting error

i am trying to work on a simple shell script as

Code:
#!/bin/bash
filename = $2
if [ "$1" = "-cat" ]; then
echo " Displaying the Content of the file:"
filename = $2
cat filename
else
if [ "$1" = "-ls"]; then
echo "Displaying directory listing:"
ls -l filename
else
echo " Commands not correct:"
fi
done


it shows the error
line 14: syntax error near unexpected token 'done'
line 14: 'done'
i am using bash shell in ubantu..

thank you and regards

edit by bakunin: please use CODE-Tags when posting code. It greatly enhances readability and it cheers up the venerable cfajohnson to no end. I have inserted them now for you.

Last edited by bakunin; 03-30-2009 at 06:18 AM..
# 2  
Old 03-29-2009
for each if statement should end with a fi

you are missing with a fi.
# 3  
Old 03-29-2009
Quote:
Originally Posted by phone_book
i am trying to work on a simple shell script as

Please put code inside [code] tags.
Quote:
Code:
#!/bin/bash
filename = $2


When posting code, please do not retype it; insert the script file or cut and paste the code. The previous line would have given you an error if that is what you actually were running.

Code:
filename=$2

Quote:
Code:
if [ "$1" = "-cat" ]; then
echo " Displaying the Content of the file:"
filename = $2


Redundant, with the same error as above.
Quote:
Code:
cat filename


Do you mean:

Code:
cat "$filename"

Quote:
Code:
else
if [ "$1" = "-ls"]; then
echo "Displaying directory listing:"
ls -l filename


Do you mean:

Code:
ls -l "$filename"

Quote:
Code:
else
echo " Commands not correct:"
fi
done

it shows the error
line 14: syntax error near unexpected token 'done'
line 14: 'done'

You don't have a do to close with done.
# 4  
Old 03-29-2009
This lends itself to a "case" statement.

Code:
#!/bin/bash
action="$1"
filename="$2"
#
case "${action}" in
        "-cat")
               echo "Displaying the Content of the file:"
               cat "${filename}"
               ;;
        "-ls")
               echo "Displaying directory listing:" 
               ls -l "${filename}"
               ;;
        *)
               echo "Commands not correct:"
               echo "Usage scriptname [-ls | -cat] filename"
               ;;
esac

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell scripting syntax error in if then else

I have one bash shell script to execute table refreshment. At the bottom of script, I have one piece of code to check 'ORA-' error from log file, then send email to DBA or application people. But this piece of code didn't work. I tried different ways and also search online to find where is my... (2 Replies)
Discussion started by: duke0001
2 Replies

2. Shell Programming and Scripting

Error in tsch shell scripting..

Hi Everyone, I am using gdb-7.5 to connect to the target. When I gave the./configure --target=xyz --build=i686-pc-mingw32 --host=i686-pc-mingw32 command then checking build system type... i686-pc-mingw32 checking host system type... i686-pc-mingw32 checking target system type... xyz-mingw32... (3 Replies)
Discussion started by: Heeka
3 Replies

3. Shell Programming and Scripting

Shell Scripting Error - help

I am trying to do an upgrade on a VMWare appliance. I am getting an error, and I dug into the script that is causing the error and will post the statement that is causing the error. Basically, my software seems to want an additional partition before it will do the upgrade. So, I added a new... (1 Reply)
Discussion started by: Phoenix Askevic
1 Replies

4. Shell Programming and Scripting

ERROR in executing mysql querys in shell scripting

Hi All, Please see the below script for mysql 3 commands. Its giving me the right output for all three commands but showing some errors in first two commands , i guess there might be an issue with date. Can anyone help me . #! /bin/bash TABLE_NAME=testingddatabase USER_NAME=root... (3 Replies)
Discussion started by: aish11
3 Replies

5. Shell Programming and Scripting

shell scripting error help

Im tryign to write a script that counts the number of new lines in the file with the most new lines in a given directory i keep getting this error /export/home/sieben01/itec400/homework> ./maxlines.sh ./maxlines.sh: syntax error: `then' unexpected operator/operand any ideas? ... (11 Replies)
Discussion started by: livewire06
11 Replies

6. Shell Programming and Scripting

Call Shell scripting from Perl Scripting.

Hi How to call a shell scripting through a Perl scripting? Actually I need some value from Shell scripting and passes in the Perl scripting. So how can i do this? (2 Replies)
Discussion started by: anupdas
2 Replies

7. Shell Programming and Scripting

Error handling in Unix shell scripting

Hello, I have written a shell script and suppose there is any error in the script. How i can do exception handling in shell script.for example i have below code sqlplus -s <<uid>>/<<pwd>>@<<$ORACLE_SID>> <<EOF > 1_pid1.log set pagesize 0 set feedback off set heading off set linesize 200... (1 Reply)
Discussion started by: rksingh003
1 Replies

8. Shell Programming and Scripting

bash shell scripting error need help urgently

#! /bin/sh abcd = "Hello world" if then echo $abcd fi i got error message that line3 : abcd: command not found line5 : [0: command not found line5 : [1: command not found i have no idea why i got this message. Can some one help me ??? (6 Replies)
Discussion started by: bonosungho
6 Replies

9. Shell Programming and Scripting

Shell Scripting Error

When i run the script firecall.sh,i am getting a weird error. root: ./var/ADMIN/bin/firecall.sh d12381 ./var/ADMIN/bin/firecall.sh: ?osrc: command not found ./var/ADMIN/bin/firecall.sh: ?osrc: command not found The script is successful,but the error interests me...Any Ideas?? The... (1 Reply)
Discussion started by: Renjesh
1 Replies

10. Shell Programming and Scripting

difference between AIX shell scripting and Unix shell scripting.

please give the difference between AIX shell scripting and Unix shell scripting. (2 Replies)
Discussion started by: haroonec
2 Replies
Login or Register to Ask a Question