Computing.Net > Forums > Linux > Bash Script Unexpected end of file

Bash Script Unexpected end of file

Reply to Message Icon

Original Message
Name: littlemissknit
Date: March 10, 2005 at 18:29:53 Pacific
Subject: Bash Script Unexpected end of file
OS: Red Hat Linux
CPU/Ram: IBM clone
Comment:

Thanks for the great tip, its worked great!
now i'm trying to fix an end of file problem. I've programmed this file to delete all zero length files and i keep getting an end of file error
#!/bin/bash

if [$1 == -f]
then
find $2 -empty -print -exec rm -f {}\
else
find $1 -empty -ok rm -f {}\
fi


i've tried adding "done" "exit" and "exit 0"
there is definetly something I'm missing here!

Littlemissknit


Report Offensive Message For Removal


Response Number 1
Name: Xavier HECQUET
Date: March 11, 2005 at 04:00:31 Pacific
Reply: (edit)

Don't forget the "point-comma" (excuse-me, I'm french, don't know the real name) : ";"

I think some spaces are also missing.

I think this should be:

if [$1 == -f]
then
find $2 -empty -print -exec rm -f {} \;
else
find $1 -empty -ok rm -f {} \;
fi

Regards

Xavier


Report Offensive Follow Up For Removal

Response Number 2
Name: littlemissknit
Date: March 11, 2005 at 06:34:28 Pacific
Reply: (edit)

i entered what you said and it said that for the "if [$1 == -f]" that i'm missing a ']' but i closed the line like you did in the file.
it also says i'm missing an argument to "-ok'


Report Offensive Follow Up For Removal

Response Number 3
Name: kk7av
Date: March 24, 2005 at 23:40:02 Pacific
Reply: (edit)

Try adding quotes. Ex:

if [ "$1" = "-f" ]

All of the Bash shell scripts I've written required the arguments to be quoted. Also in Bash, I think you can use a single equals sign for evaluation. See the following for some examples:

http://www.tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-6.html#ss6.3

Good luck!


Rob Pectol
http://rob.pectol.com/


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Bash Script Unexpected end of file

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




Have you ever used OpenOffice?

Yes, as my main suite.
Yes, occationally.
Yes, but only once.
No, never.


View Results

Poll Finishes In 6 Days.
Discuss in The Lounge