Operating System - HP-UX
1836612 Members
3765 Online
110102 Solutions
New Discussion

Re: "GOTO" in a korn shell script

 
SOLVED
Go to solution

"GOTO" in a korn shell script

Hello Gang,

I have a ksh script that has me stumped. I have added an "if-then-else-fi" around some existing code that used to all run unconditionally, and now I've created a problem. Can it be the here file ( << endofsort) causing the problem? As always, I appreciate your help. I haven't stumped you yet:-)

This is the block of code that has the problem:

if [[ $_pass1 = "1" ]]
then
syncsort 2>> testfile << endofsort
/infile pas1800.dbasub00 fixed 240
/infile ps2001p.p27510 fixed 240
/fields f1 1 131 character
/keys f1
/outfile pas1800.dbasub00.pass1.memo fixed 240
/statistics
/end
endofsort
export RTNCODE=`echo $?`
echo Return code is $RTNCODE >> testfile
case $RTNCODE in
0) ;;
*) echo $STEP TERMINATED ABNORMALLY !!!!!!!!!! |tee -a testfile
echo Error Code $RTNCODE |tee -a testfile
exit $RTNCODE ;;
esac
#
else
cp pas1800.dbasub00 pas1800.dbasub00.pass1.memo
7 REPLIES 7
James R. Ferguson
Acclaimed Contributor
Solution

Re: "GOTO" in a korn shell script

Hi Weary:

Make sure that your 'endofsort' begins at the leftmost character (the first) on the line.

Regards!

...JRF...
Rodney Hills
Honored Contributor

Re: "GOTO" in a korn shell script

I don't see "fi" to close the if-then block.

-- Rod Hills
There be dragons...

Re: "GOTO" in a korn shell script

Gosh James, you're the best. That's all it was. We indented to make it "pretty". Well, so much for looking good. It's working fine now. Thanks so much.
James R. Ferguson
Acclaimed Contributor

Re: "GOTO" in a korn shell script

Hi (again) Weary:

/No_Points_Please/

I like pretty, rigourously indented code too, but this is one case where you have to abide by a "higher rule" :-)

Glad to have been of help.

Regards!

...JRF...
Martin Robinson
Frequent Advisor

Re: "GOTO" in a korn shell script

Although the normal '<< EOF' here-document insists that the ending token (EOF) is hard up against the left margin, the alternative form '<<- EOF' does not require this. But it will strip leading white space from your here document, which is why it works.

Example:
cat <<- EOF
hello 1
hello 2
EOF

produces
hello 1
hello 2

Re: "GOTO" in a korn shell script

Martin,

Thanks for the additional info. I checked the man page (ksh - TRU64 Unix) and found that the "-" just strips off tabs from the beginning of the here document and not all white space. With tabs, it works like a champ.
Tom Danzig
Honored Contributor

Re: "GOTO" in a korn shell script

Martin stated that "the alternative form '<<- EOF' does not require this. But it will strip leading white space from your here document, which is why it works. "

Keep in mind that this works WITH TABS ONLY; not spaces.