Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

syntax error on simple, simple change-case script

Status
Not open for further replies.

natv

Programmer
Jun 5, 2007
3
Hey guys,

I'm learning bash scripting through self study and in a video training the instructor is demonstrating a script that converts lowercase file names to uppercase to help learn some basics.

I've copied the script from the screen, and looked over it 50 times and I'm almost certain that I've copied it correctly, but I get an error when I run it (and it works for the instructor)

So I must be doing something wrong. This is the simple script:

Code:
#!/bin/bash
#Purpose: Illustrate using tr in a script to convert upper to lower file names

myscriptname=`basename $0` ;

for i in `ls -A`
do
        if [ $i = $myscriptname ]
        then
         echo "Sorry, can't rename myself!"
        elif [ $i != $myscriptname ]
         newname=`echo $i | tr a-z A-Z`
         mv $i $newname
        fi
done

#END


When I run it, I get:


# ./tr1.sh
./tr1.sh: line 14: syntax error near unexpected token `fi'
./tr1.sh: line 14: ` fi'



line 14 just has "fi".

I also tried using spaces instead of tabs to intent it, but that didn't make any difference.

Any idea what I'm missing? If it helps I'm using CentOS 4.4 and the bash version is bash-3.0-19.3


Thanks
Nat


 
Replace this:
elif [ $i != $myscriptname ]
with either this:
elif [ $i != $myscriptname ]; then
or simply this:
else

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thank you, yes that does help :)

Especially the short-cut version of just using "else"


Thanks again,
Nat
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top