"else" unmatched error in shell script.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting "else" unmatched error in shell script.
# 1  
Old 02-25-2009
"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  
Old 02-25-2009
You used a wrong operator for a string comparison.

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

should be:

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

Regards
# 3  
Old 02-25-2009
Quote:
Originally Posted by Franklin52
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  
Old 02-25-2009
Quote:
mv "$1\$2" Current\*\
What is that "\" at the end of line ???
# 5  
Old 02-25-2009
You are using DOS directory sep "\" instead of UNIX directory sep "/".

I'd probably go with:


Code:
mv $1/$2 Current/

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. HP-UX

HP-UX: Shell Script giving " 0^J30: Syntax error"

Hi All, We are getting a very unique error while running a shell script on HP-UX box. Can somebody help in this regards? The shell script is working fine on linux/solaris box. Error: ++++++++++++++++++++++++ $/test.sh ./test.sh: 0^J30: Syntax error $ ++++++++++++++++++++++++ TIA.... (16 Replies)
Discussion started by: vai_sh
16 Replies

3. Shell Programming and Scripting

Irritating Shell script problem - " unmatched

Hi, I have the below KSH shell script: #!/usr/bin/ksh if ; then echo "Usage: resourceSts <server> else if ; then source="<server>" ssh <userid>@$source > output 2>/dev/null <<_EOF scstat -g _EOF elif ; then source="<server>" ssh... (5 Replies)
Discussion started by: chris01010
5 Replies

4. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

5. Shell Programming and Scripting

read -n1 -r -p "Press..." key / produces error in bash shell script

Hello! Sorry, for my not so perfect english! I want to stop bash shell script execution until any key is pressed. This line in a bash shell script read -n1 -r -p "Press any key to continue..." key produces this error When I run this from the command line usera@lynx:~$ read... (4 Replies)
Discussion started by: linuxinho
4 Replies

6. Shell Programming and Scripting

Error with "multiplication table" in shell script

#!/bin/sh echo Enter the multiplication number required: read number for i in 1 2 3 4 5 6 7 8 9 10 do echo "$number * $i = expr $number \* $i" done I am not getting the output for this multiplication table. (4 Replies)
Discussion started by: vinodpaw
4 Replies

7. AIX

"too big" and "not enough memory" errors in shell script

Hi, This is odd, however here goes. There are several shell scripts that run in our production environment AIX 595 LPAR m/c, which has sufficient memory 14GB (physical memory) and horsepower 5CPUs. However from time to time we get the following errors in these shell scripts. The time when these... (11 Replies)
Discussion started by: jerardfjay
11 Replies

8. Shell Programming and Scripting

"<< Unmatched" in ksh script using sftp

Getting "syntax error at line 19: `<<' unmatched" trying to run sftp in a ksh script. ...snip... 13 for each in $HOSTS; 14 do 15 if ; 16 then mkdir /usr/restore/$each 17 fi 18 cd /usr/restore/$each 19 sftp -b - server-1 <<EOF 20 get... (6 Replies)
Discussion started by: michaelak28
6 Replies

9. Shell Programming and Scripting

Getting error "syntax error at line 78 : `<' unmatched"

Hi Guys, I have a following code in cm1.sh script. cnt=`sqlplus -s <un>/<pwd> << !EOF set heading off verify off pagesize 0 select count(*) from fnd_svc_components where component_name like '%Mailer%' and component_status != 'RUNNING'; exit; !EOF` echo $cnt if ; then sqlplus -s... (1 Reply)
Discussion started by: sshah1001
1 Replies

10. UNIX for Dummies Questions & Answers

No utpmx entry: you must exec "login" from lowest level "shell"

Hi I have installed solaris 10 on an intel machine. Logged in as root. In CDE, i open terminal session, type login alex (normal user account) and password and i get this message No utpmx entry: you must exec "login" from lowest level "shell" :confused: What i want is: open various... (0 Replies)
Discussion started by: peterpan
0 Replies
Login or Register to Ask a Question