![]() |
|
|
|
|
|||||||
| 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 !! |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
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 | ||
|
|
|
|||
|
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 |
|
||||
|
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. |
|
|||
|
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 |
|
|||
|
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 |
|
||||
|
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 |
|
||||
|
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). |
|
|||
|
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. |
|
||||
|
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 |
|
||||
|
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 |
| 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 |