LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 09-30-2009, 10:30 AM   #1
divyashree
Senior Member
 
Registered: Apr 2007
Location: bbsr,orissa,India
Distribution: RHEL5 ,RHEL4,CENT OS5,FEDORA,UBUNTU
Posts: 1,356

Rep: Reputation: 135Reputation: 135
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
 
Old 09-30-2009, 10:38 AM   #2
weibullguy
ReliaFree Maintainer
 
Registered: Aug 2004
Location: Kalamazoo, Michigan
Distribution: Slackware-current, Cross Linux from Scratch, Gentoo
Posts: 2,755
Blog Entries: 1

Rep: Reputation: 238Reputation: 238Reputation: 238
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
 
Old 09-30-2009, 10:51 AM   #3
divyashree
Senior Member
 
Registered: Apr 2007
Location: bbsr,orissa,India
Distribution: RHEL5 ,RHEL4,CENT OS5,FEDORA,UBUNTU
Posts: 1,356

Original Poster
Rep: Reputation: 135Reputation: 135
Quote:
Originally Posted by weibullguy View Post
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 !!!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
syntax error near unexpected token `fi' Warmduvet Programming 21 10-08-2013 11:28 AM
why am getting error ksh: syntax error: `fi' unexpected while running script deb4you Linux - Newbie 4 09-06-2008 09:37 AM
compiling error: unexpected token `fi' rem1986 Linux - Kernel 7 12-10-2007 02:11 PM
syntax error near unexpected token `fi' sureshkumar.repaka Linux - General 7 08-19-2007 11:14 PM
Trouble with Bash -- syntax error near unexpected token `fi' anamericanjoe Programming 5 05-19-2006 03:59 PM


All times are GMT -5. The time now is 06:41 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration