Register
It is currently Wed Jul 23, 2014 8:20 pm

problem with <<EOF


All times are UTC - 6 hours


Post new topic Reply to topic  [ 2 posts ] 
Author Message
 PostPosted: Thu Dec 24, 2009 3:53 pm   

Joined: Thu Dec 24, 2009 3:46 pm
Posts: 1
Hi there i have a problem, i have a script as follows:
----------------------
#!/bin/bash

if [ $1 = "OK" ]; then
mailto -s "Success" mymail@home.com <<EOF
Hi,
The operation has succeeded.
EOF

elif [$1 = "ERROR" ]; then
mailto -s "Error" mymail@home.com <<EOF
Hi,
The operation has failed.
EOF
fi
---------------------------

If an OK has been received than i get the following mail:
----------------------------
Hi,
The operation has succeeded.
EOF

elif [OK = "ERROR" ]; then
mailto -s "Error" mymail@home.com <<EOF
Hi,
The operation has failed.
EOF
fi
------------------------------

And i don't get anything when the scripts gets an ERROR argument.
In other words, the mailto command in my script doesn't see the EOF
as the end of input. Why is that? What am i doing wrong?

kind regards,

Robin


Top
 Profile  
 PostPosted: Tue Dec 29, 2009 5:34 am   
Moderator
User avatar

Joined: Thu Oct 11, 2007 7:12 am
Posts: 229
Location: London - UK
The <<EOF works correctly (tested in bash 4.0.33), I note that the script you provide errors due to a missing space. I do not have the mailto command but I suggest you try a simpler script that will work and expand it out to what you need;

Code:
#!/bin/bash

if [ "$1" = "OK" ]; then
cat <<EOF
Hi,
The operation has succeeded.
EOF

elif [ "$1" = "ERROR" ]; then
cat <<EOF
Hi,
The operation has failed.
EOF
fi


I do not believe that the mailto command itself has anything to do with the use of <<EOF as that is a bash function for piping the content into STDIN.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot] and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP