LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   syntax error near unexpected token `fi' (https://www.linuxquestions.org/questions/programming-9/syntax-error-near-unexpected-token-%60fi-758685/)

divyashree 09-30-2009 09:30 AM

syntax error near unexpected token `fi'
 
I am just learning how to write a script and this is my 1st script to change the case of the filenames in the current directory.I am using RHEL5 server.
But each time I execute this it says
Code:

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

Is there any error in this script ??I am unable to identify the error.
Code:

#!/bin/bash
#Author: Priyadarshee Divyashree kumar
#Date: 28-09-2009


#clear
myscriptname=`basename $0`;

for i in `ls -A`

do
        if [ $i = $myscriptname ]
          then
          echo "Sorry, can't apply script on $myscriptname!"
        elif [ $i != $myscriptname ]
          newname=`echo $i | tr a-z A-Z`
          mv $i $newname
        fi
done

#END


weibullguy 09-30-2009 09:38 AM

You need a then after the elif or you need to replace the entire elif line with else
Code:

elif [ $i != $myscriptname ]
then
    newname=`echo $i | tr a-z A-Z`
    mv $i $newname
fi


divyashree 09-30-2009 09:51 AM

Quote:

Originally Posted by weibullguy (Post 3701877)
You need a then after the elif or you need to replace the entire elif line with else
Code:

elif [ $i != $myscriptname ]
then
    newname=`echo $i | tr a-z A-Z`
    mv $i $newname
fi


Hello bro,thanks a lot,but can I mention both tr A-Z a-z and tr a-z A-Z ,so that,if the file names are in uppercase it'll convert into lower and if in lower it'll convert into upper !!!


All times are GMT -5. The time now is 01:14 AM.