Operating System - Linux
1827811 Members
1864 Online
109969 Solutions
New Discussion

Re: <<EOF is not matched ?

 
SOLVED
Go to solution
Coolmar
Esteemed Contributor

<<EOF is not matched ?

I have the following in my script, and get the error in the subject...why is this not working?

mail -t $mailgroup < Subject: $subjetc
From: $name
Cc: $dbgroup
this is the text
EOF
8 REPLIES 8
Patrick Wallek
Honored Contributor

Re: <<EOF is not matched ?

Try putting a space between << and EOF.

mail -t $mailgroup << EOF
Subject: $subjetc
From: $name
Cc: $dbgroup
this is the text
EOF
James R. Ferguson
Acclaimed Contributor
Solution

Re: <<EOF is not matched ?

Hi:

Make sure that you EOF is flush left --- i.e. without any leading whitespace.

Regards!

...JRF...
Coolmar
Esteemed Contributor

Re: <<EOF is not matched ?

I tried that....I have put it in a case statement so perhaps that is the problem:

case "$name" in
A)
mail -t $mailb < Subject: $groupbsubj
From: $name
Cc: $dbagroup
text
EOF
;;
B)
etc etc etc

The error I get is actually Syntax error at line 18 : `<<' is not matched
Patrick Wallek
Honored Contributor

Re: <<EOF is not matched ?

I just tried it in a case statement and it works fine.

#!/usr/bin/sh

THING=$1

case $THING in

A)
mail -t $mailgroup << EOF
Subject: $subjetc
From: $name
Cc: $dbgroup
this is the text
EOF
echo "A"
;;

B)
echo "B"
;;
esac


I invoked my script as './script.sh A' and it echoed A to the screen and I got the email.

Make absolutely SURE that you do NOT have any spaces before the last EOF. Putting ' EOF' after the mail text is the only way I've duplicated your problem.
Coolmar
Esteemed Contributor

Re: <<EOF is not matched ?

Yep, it all had to be flush left. That fixed it. Thanks!
Bill Hassell
Honored Contributor

Re: <<EOF is not matched ?

You've probably noticed that the Forums removes extra spaces. You can indent the text in your 'here document' between the << EOF and the actual EOF string. The important rule is that the termination string must start in column 1 (flush left). Anything before that string has no restrictions on spacing.


Bill Hassell, sysadmin
spex
Honored Contributor

Re: <<EOF is not matched ?

Hi,

Just FYI, bash has the <<- redirection operator, which strips leading tabs from the here-document.

PCS
Steven Schweda
Honored Contributor

Re: <<EOF is not matched ?

> You've probably noticed that the Forums
> removes extra spaces. [...]

Actually, it (they?) doesn't, but a
normal/typical Web browser does. "View
document source" (or whatever your browser
calls it), and the indentation is more
obvious. In this case, it all looked better
here than it must have in reality. (That is,
no obvious space before the terminating
"EOF".)