Shell Programming and Scripting

BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Comparing Two Strings

👤 Login to reply

 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-09-2008
Anji Anji is offline
Registered User
 
Join Date: Jan 2008
Last Activity: 10 December 2010, 2:38 AM EST
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Comparing Two Strings

Hi All,
While I am trying to run below code I Am getting the exception like

./abs.sh: line 102: syntax error near unexpected token `then'
./abs.sh: line 102: ` then'


The Code Snippet is:

if[ "$file1" = "Sector.sql" || "$file1" = "Currency.sql" ] then
cat $file1 | sed -e "s/DB_NAME/${DBNAME}/g" > $LOG_DIR/$file1
$ISQL -U$USER -P$PASSWD -S$SERVERNAME < $LOG_DIR/$file1
echo "$LOG_DIR/$file1 file::::::::"
rm $LOG_DIR/$file
else
. $file1
fi

Can Anybody help me out to rectify that exception.

Thanks,
Anji
Sponsored Links
    #2  
Old 01-09-2008
ranjithpr ranjithpr is offline
Registered User
 
Join Date: Nov 2007
Last Activity: 20 August 2010, 3:34 AM EDT
Posts: 175
Thanks: 0
Thanked 3 Times in 3 Posts
syntax problem

either u should give
if[ "$file1" = "Sector.sql" || "$file1" = "Currency.sql" ]; then
or
if[ "$file1" = "Sector.sql" || "$file1" = "Currency.sql" ]
then
Sponsored Links
    #3  
Old 01-09-2008
Anji Anji is offline
Registered User
 
Join Date: Jan 2008
Last Activity: 10 December 2010, 2:38 AM EST
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Thank buddy,
I have tried that logic too...

but still I am getting the following Exception

Code Snippet:
if["$file1" = "Sector.sql" || "$file1" = "Currency.sql"]; then
cat $file1 | sed -e "s/DB_NAME/${DBNAME}/g" > $LOG_DIR/$file1
$ISQL -U$USER -P$PASSWD -S$SERVERNAME < $LOG_DIR/$file1
echo "$LOG_DIR/$file1 file::::::::"
rm $LOG_DIR/$file
else
. $file1
fi

Exception:

./abs.sh: line 101: syntax error near unexpected token `then'
./abs.sh: line 101: ` if["$file1" = "Sector.sql" || "$file1" = "Currency.sql"]; then '
    #4  
Old 01-09-2008
ranjithpr ranjithpr is offline
Registered User
 
Join Date: Nov 2007
Last Activity: 20 August 2010, 3:34 AM EDT
Posts: 175
Thanks: 0
Thanked 3 Times in 3 Posts
missing spaces and use -o for OR

if [ "$file1" = "Sector.sql" -o "$file1" = "Currency.sql" ]; then
Sponsored Links
    #5  
Old 01-09-2008
Anji Anji is offline
Registered User
 
Join Date: Jan 2008
Last Activity: 10 December 2010, 2:38 AM EST
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Hi,
Thanks for your reply...
Sorry to say that
I have tried with the command which you have given.
but also I am getting the same error....

Code:
if[ "$file1" = "Sector.sql" -o "$file1" = "Currency.sql"]; then
cat $file1 | sed -e "s/DB_NAME/${DBNAME}/g" > $LOG_DIR/$file1
$ISQL -U$USER -P$PASSWD -S$SERVERNAME < $LOG_DIR/$file1
echo "$LOG_DIR/$file1 file::::::::"
rm $LOG_DIR/$file

else
. $file1
fi

Error:
./BatchJobs.sh: line 101: syntax error near unexpected token `then'
./BatchJobs.sh: line 101: ` if[ "$file1" = "Sector.sql" -o "$file1" = "Currency.sql"]; then'



Can u help me out plz....

---Anji
Sponsored Links
    #6  
Old 01-09-2008
ranjithpr ranjithpr is offline
Registered User
 
Join Date: Nov 2007
Last Activity: 20 August 2010, 3:34 AM EDT
Posts: 175
Thanks: 0
Thanked 3 Times in 3 Posts
Its not the same code one space is missing

if[ "$file1" = "Sector.sql" -o "$file1" = "Currency.sql"]; then

if[ "$file1" = "Sector.sql" -o "$file1" = "Currency.sql" ]; then
Sponsored Links
    #7  
Old 01-09-2008
Anji Anji is offline
Registered User
 
Join Date: Jan 2008
Last Activity: 10 December 2010, 2:38 AM EST
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
I have given the space too

but I am getting the same error as above.....

This silly mistake making me lot of trouble

Can you plz help me out..........

thanks
anji
Sponsored Links
👤 Login to reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Comparing strings with sed cola Shell Programming and Scripting 7 08-22-2010 11:51 AM
comparing two strings infyanurag Shell Programming and Scripting 1 10-15-2008 02:38 AM
comparing 2 strings satish@123 Shell Programming and Scripting 2 05-16-2008 07:59 AM
comparing strings agarwal Shell Programming and Scripting 3 04-16-2008 05:29 AM
Comparing strings yakyaj UNIX for Advanced & Expert Users 2 03-23-2007 01:22 AM



All times are GMT -4. The time now is 06:12 PM.

Unix & Linux Forums Content Copyright©1993-2018. All Rights Reserved.
×
UNIX.COM Login
Username:
Password:  
Show Password





Not a Forum Member?
Forgot Password?