LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 01-23-2018, 04:06 PM   #1
Cheryl_A
LQ Newbie
 
Registered: Mar 2013
Location: USA
Posts: 2

Rep: Reputation: Disabled
Lightbulb KSH script error -ksh: .: syntax error: `<<' unmatched


I'm posting with the solution. The OS I'm working with is Red Hat Enterprise Linux (RHEL) 7.2.

I'm working with a script to execute an oracle procedure. The first and last lines are:
sqlplus -S /NOLOG << EOF >> $LOGFILE 2>>$LOGFILE

exit
EOF

I copied the lines verbatim from a working korn shell script, but when I went to execute it I got
-ksh: .: syntax error: `<<' unmatched

Searching the documentation says there is some kind of missing character, or line feed, or a space in the first position of a line between the two EOFs. I compared the working and non-working scripts in TextPad and using vi. (We use a mishmash of PC tools and command line edits when we work with scripts.) Nothing seemed mismatched.
Solution:
I ran the file command in the Linux server environment:
file run_WH_Monthly_PYR20.ksh

here's the result:
run_WH_Monthly_PYR20.ksh: Korn shell script, ASCII text executable, with CRLF line terminators

I edited the script in TextPad and did a Save As - the file format was PC. I saved it as file format UNIX and tried the file command again:
file run_WH_Monthly_PYR20.ksh
run_WH_Monthly_PYR20.ksh: Korn shell script, ASCII text executable

I tried to execute again. This time no syntax errors - the script ran perfectly.

I'm sure there's a Linux command solution that would reformat the script, but this worked for me.
 
Old 01-24-2018, 03:33 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,930

Rep: Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321
you may try to use shellcheck to catch those errors.
 
1 members found this post helpful.
Old 01-24-2018, 10:27 AM   #3
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,735

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Quote:
Originally Posted by Cheryl_A View Post
I'm posting with the solution. The OS I'm working with is Red Hat Enterprise Linux (RHEL) 7.2.

I'm working with a script to execute an oracle procedure. The first and last lines are:
sqlplus -S /NOLOG << EOF >> $LOGFILE 2>>$LOGFILE

exit
EOF

I copied the lines verbatim from a working korn shell script, but when I went to execute it I got
-ksh: .: syntax error: `<<' unmatched

Searching the documentation says there is some kind of missing character, or line feed, or a space in the first position of a line between the two EOFs. I compared the working and non-working scripts in TextPad and using vi. (We use a mishmash of PC tools and command line edits when we work with scripts.) Nothing seemed mismatched.
Solution:
I ran the file command in the Linux server environment:
file run_WH_Monthly_PYR20.ksh

here's the result:
run_WH_Monthly_PYR20.ksh: Korn shell script, ASCII text executable, with CRLF line terminators

I edited the script in TextPad and did a Save As - the file format was PC. I saved it as file format UNIX and tried the file command again:
file run_WH_Monthly_PYR20.ksh
run_WH_Monthly_PYR20.ksh: Korn shell script, ASCII text executable

I tried to execute again. This time no syntax errors - the script ran perfectly.

I'm sure there's a Linux command solution that would reformat the script, but this worked for me.
The linux command is dos2unix. It converts the End Of Line (EOL) characters from DOS/Windows' CRLF to linux's LF.

Alternatively, if using FTP/SFTP to transfer a file, using ascii mode will convert the EOL characters from CRLF to LF

And yes, one gets unclear error messages in unix sometimes when a script has CRLF line ends.
 
1 members found this post helpful.
  


Reply

Tags
ksh



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
KSH - Script error; invalid command - boyd98 Programming 4 07-19-2012 10:22 AM
syntax error in ksh script barkha_st Linux - Newbie 12 08-25-2011 03:24 AM
ksh syntax error: `(' unexpected SentralOrigin Programming 5 11-10-2010 02:57 PM
why am getting error ksh: syntax error: `fi' unexpected while running script deb4you Linux - Newbie 4 09-06-2008 08:37 AM
Porting ksh script from Solaris to Linux Gives unmatched if error markatharvestinfotec Programming 4 08-28-2008 01:51 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 08:43 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration