The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
"too big" and "not enough memory" errors in shell script jerardfjay AIX 11 03-16-2009 11:09 PM
ERROR: more than one instance of overloaded function "vprintf" has "C" linkage donatoll HP-UX 0 10-14-2008 06:35 AM
"<< Unmatched" in ksh script using sftp michaelak28 Shell Programming and Scripting 6 08-28-2008 09:49 AM
Getting error "syntax error at line 78 : `<' unmatched" sshah1001 Shell Programming and Scripting 1 05-08-2008 06:41 PM
No utpmx entry: you must exec "login" from lowest level "shell" peterpan UNIX for Dummies Questions & Answers 0 01-18-2006 04:15 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-25-2009
Renjesh Renjesh is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 84
"else" unmatched error in shell script.

Friends

I have pasted a script below

[36]d08083: cat tests
#!/bin/ksh
if [ "$2" -eq "" ]
then
rm -r Last-Previous
mv Previous Last-Previous
mv Current Previous
mkdir Current
#cd Current
mv $1 Current
else
cd Current
mv "$1\$2" Current\*\
fi


cheux301 @ /users/d08083
[37]d08083: ./tests
./tests[2]: syntax error at line 10 : `else' unmatched
cheux301 @ /users/d08083


Any idea why i am getting the error!!

Thanks
HG
  #2 (permalink)  
Old 02-25-2009
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,342
You used a wrong operator for a string comparison.


Code:
if [ "$2" -eq "" ]

should be:


Code:
if [ "$2" = "" ]

Regards
  #3 (permalink)  
Old 02-25-2009
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,374
Quote:
Originally Posted by Franklin52 View Post
You used a wrong operator for a string comparison.


Code:
if [ "$2" -eq "" ]

should be:


Code:
if [ "$2" = "" ]

Regards

Better (perhaps) would be:


Code:
if [ -z "$2" ]

  #4 (permalink)  
Old 02-25-2009
Goldorakk's Avatar
Goldorakk Goldorakk is offline
Registered User
  
 

Join Date: Feb 2009
Location: France
Posts: 43
Quote:
mv "$1\$2" Current\*\
What is that "\" at the end of line ???
  #5 (permalink)  
Old 02-25-2009
rmoncello's Avatar
rmoncello rmoncello is offline
Registered User
  
 

Join Date: Feb 2009
Location: Frisco, TX
Posts: 22
You are using DOS directory sep "\" instead of UNIX directory sep "/".

I'd probably go with:



Code:
mv $1/$2 Current/

Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:39 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0