The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Getting error "syntax error at line 78 : `<' unmatched" sshah1001 Shell Programming and Scripting 1 05-08-2008 02:41 PM
"<< Unmatched" in ksh script using sftp michaelak28 Shell Programming and Scripting 5 03-27-2008 10:11 AM
list of unmatched columns mohan705 Shell Programming and Scripting 3 12-12-2007 06:37 AM
else unmatched b.hamilton Shell Programming and Scripting 7 10-10-2007 02:03 AM
Delete unmatched data nazri76 Shell Programming and Scripting 5 07-16-2006 03:41 AM

Closed Thread
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-04-2001
Registered User
 

Join Date: Aug 2001
Location: South Carolina
Posts: 18
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
Unmatched 'then'

I am having a problem with the following statement in a korn shell script:

if "$all_recs" = "ALL"; then

commands

fi;

I keep getting the error syntax error at line 999 : 'then' unmatched.

I'm sure it is a minor problem, but have been unable to find any answers online. Any help would be appreciated. Also appreciated are any good online sources for korn shell scripting.

Thanks,

Amber Taylor


Forum Sponsor
  #2 (permalink)  
Old 09-04-2001
PxT's Avatar
PxT PxT is offline
Registered User
 

Join Date: Oct 2000
Location: Sacramento, CA
Posts: 903
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
You should enclose your if statement in square brackets:

Code:
if [ "$all_recs" = "ALL" ]
then
	commands
fi
  #3 (permalink)  
Old 09-04-2001
Registered User
 

Join Date: Aug 2001
Location: South Carolina
Posts: 18
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
Thank you for your response.


I made the changes you suggested and now I have the syntax error at line 999 : 'if' unmatched. Now the statement looks like:

if ["$all_recs" = "NEW"] then

commands

fi;

Also, I am coding behind someone and many of the if statements they used do not have the []'s around them. They are formatted like:

if test $# -ne 3;
then

commands

fi;

--or--

if test $file_ext = "file_ext";
then
continue;
fi;

Why would they above work, but not the one I did?

Thanks Again,

Amber Taylor
  #4 (permalink)  
Old 09-04-2001
patvdv's Avatar
Registered User
 

Join Date: Jul 2001
Location: Belgium
Posts: 83
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
The answer is simple: you either use the test construction -or- square brackets. Also to keep coding simple and avoid having to use semicolons all the the time to delimit commands, put the several components of the if-then-else-fi construct on separate lines:

Code:
if [ condition ]
then
       command 1
else
       command 2
fi
In your case, you were missing a semicolon just before the 'then'
__________________
Patrick Van der Veken - UNIX consultant (c) 2001 - 2001 http://www.baanboard.com - http://www.ux-core.com
'True strength lies in gentleness' - Irish proverb
  #5 (permalink)  
Old 09-04-2001
rwb1959's Avatar
Registered User
 

Join Date: Aug 2001
Location: Virginia, USA
Posts: 438
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
The use of square brackets is another way
of using the "test" command. Note on the
square brackets... You must have a white
space after the open bracket and before the
close bracket: [ "$somevar" = "somestring" ]

The code: if "$all_recs" = "ALL"; then

...neither had the "test" nor the [ ] and you
need one OR the other.
  #6 (permalink)  
Old 09-04-2001
Registered User
 

Join Date: Aug 2001
Location: South Carolina
Posts: 18
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!


Now I am getting the 'then' unmatched again.

Here is exactly what the statement looks like:

if [ "$all_recs" = "NEW" ]
then

# Flush the staging table
echo "=== Cleaning the staging table..."
sqlplus -s $connect_string > /dev/null << EOF
begin
iws_clean_staging_pkg.iws_clean_staging_prc;
end;
/
EOF
fi;


Is there a man entry for the if statement? If so, what keyword is it under?

Thanks,

Amber Taylor
  #7 (permalink)  
Old 09-04-2001
Registered User
 

Join Date: Aug 2001
Location: South Carolina
Posts: 18
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
Also, $all_recs is a command line argument. I don't know if that makes a difference. Thank you for your earlier reply, I would have never known that spaces were needed inside the brackets!

Regards,

Amber Taylor
  #8 (permalink)  
Old 09-04-2001
Registered User
 

Join Date: Aug 2001
Location: Ontario, Canada
Posts: 20
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
Try this,

if [ conditions ] <b>;</b>
then
commands......
fi
  #9 (permalink)  
Old 09-04-2001
Registered User
 

Join Date: Aug 2001
Location: South Carolina
Posts: 18
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
Thanks, but I am still getting the same error. I have tried the semicolon's just about every which way I can.

Amber Taylor
  #10 (permalink)  
Old 09-04-2001
patvdv's Avatar
Registered User
 

Join Date: Jul 2001
Location: Belgium
Posts: 83
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
Semi's

Amber,

Get of rid of all your semicolons - except the ones in the 'here' statement and put all your commands on a separate line. There's no man page for 'if' as it is not an external command but rather a shell built-in.
__________________
Patrick Van der Veken - UNIX consultant (c) 2001 - 2001 http://www.baanboard.com - http://www.ux-core.com
'True strength lies in gentleness' - Irish proverb
  #11 (permalink)  
Old 09-04-2001
rwb1959's Avatar
Registered User
 

Join Date: Aug 2001
Location: Virginia, USA
Posts: 438
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
A couple of things...

First, remove the ";" after the "fi"
also, if $all_recs is from the command line,
I assume you are assigning it...

export all_recs=$1


Second, try changing:
sqlplus -s $connect_string > /dev/null << EOF

to:
sqlplus -s $connect_string << EOF > /dev/null

...the second part should not have anything
to do with the "unmatched then" but it may cause
you execution problems. Additionally, the "if"
command is a shell built-in and would be
documented in the KSH(1) man page (assuming you
are using ksh (just man the shell you use).
  #12 (permalink)  
Old 09-04-2001
Registered User
 

Join Date: Aug 2001
Location: South Carolina
Posts: 18
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
Thank you all for taking the time to help me with this.

I am using ksh.

Everthing inside the if statement worked before I tried to enclose it in the if statement.

I did assign the variable and tested it with an echo.

Also, I have tested it a few times without the ';' after the fi and still it wont work.

The line listed in the syntax error corresponds to the 'then' line number in the snippets above.

The only ;'s remaining (besides the one at the end of the if line) are the ones inside the sqlplus routine.
  #13 (permalink)  
Old 09-04-2001
patvdv's Avatar
Registered User
 

Join Date: Jul 2001
Location: Belgium
Posts: 83
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
Double quotes

Then there must be double quotes missing for your here doc:

Try:

<< "EOF

and

EOF"

I am not 100% sure about the exact placement of the first double quote though...
__________________
Patrick Van der Veken - UNIX consultant (c) 2001 - 2001 http://www.baanboard.com - http://www.ux-core.com
'True strength lies in gentleness' - Irish proverb
  #14 (permalink)  
Old 09-04-2001
Registered User
 

Join Date: Aug 2001
Location: South Carolina
Posts: 18
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
What do you mean by "here doc"?

Thanks,

Amber Taylor
  #15 (permalink)  
Old 09-04-2001
patvdv's Avatar
Registered User
 

Join Date: Jul 2001
Location: Belgium
Posts: 83
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
The 'here' doc is the statements between EOF and EOF.

I am pretty sure the quoting is the problem because I vaguely remember bumping into it myself. Unfortunately I don't have access right now to one of the servers where we store similar scripts, so I can't check. Try to add the double quotes.
__________________
Patrick Van der Veken - UNIX consultant (c) 2001 - 2001 http://www.baanboard.com - http://www.ux-core.com
'True strength lies in gentleness' - Irish proverb
Google UNIX.COM
Closed Thread

Thread Tools
Display Modes


The 50 most popular UNIX and Linux searches.
Google Search Cloud for The UNIX and Linux Forums
"inappropriate ioctl for device" 421 service not available, remote server has closed connection autosys awk trim bash eval bash exec bash for loop boot: cannot open kernel/sparcv9/unix close_wait command copy/move folder in unix curses.h cut command in unix dead.letter find grep find null character in a unix file grep multiple lines grep or grep recursive inaddr_any inappropriate ioctl for device logrotate.conf lynx javascript mailx attachment mget mtime ping port remove first character from string in k shell replace space by comma , perl script scp recursive segmentation fault(coredump) sftp batch sftp script snoop unix stale nfs file handle syn_sent tar exclude unix unix .profile unix com unix date command unix forum unix forums unix internals unix interview questions unix mtime unix simulator unix.com vi select all vi+substitute+end+of+line+character while loop within while loop shell script