Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 03-26-2008, 02:27 AM   #1
Registered: Feb 2006
Distribution: GNU/Linux
Posts: 54

Rep: Reputation: 15
Using /bin/mail command with a string for message, not a filename?

I know you can send an email with the contents from a file, e.g.:
mail -s "The subject" "" < /home/message.txt
But how can one specify a message directly, without having to store the message in a file name?
Old 03-26-2008, 04:16 AM   #2
Registered: May 2004
Location: Karlsruhe, Germany
Distribution: debian, gentoo, os x (darwin), ubuntu
Posts: 940

Rep: Reputation: 33
i am assuming something linke

mail -s "subject" "" <<zzzMAILzzz
this is my message text
with line breaks and everything :-)

Old 03-26-2008, 02:52 PM   #3
Registered: Feb 2006
Distribution: GNU/Linux
Posts: 54

Original Poster
Rep: Reputation: 15
So start with double less than instead of single, specify a delimiter, enter the message line by line, and then specify the same delimiter again on a line by itself to end the message? That worked, thanks.

Is there any way to do this on one line?
Old 03-26-2008, 05:53 PM   #4
Senior Member
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,138

Rep: Reputation: 166Reputation: 166
Yes, this will send the echoed message via mail:
echo "A test message" | mail -s "Test subject"
Old 03-26-2008, 08:22 PM   #5
Registered: Mar 2008
Posts: 155

Rep: Reputation: 30
You can also do
 mail -s "Test Subject" <<<"This is the message."
Check the bash man pages for "here documents" and "here strings".


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
strange filename/file in my /usr/bin directory M$ISBS Linux - Security 1 06-04-2006 07:55 PM
Filename string manipulation jango77 Linux - Newbie 2 03-27-2005 06:58 PM
how would i remove things froms filename.bin Paxmaster Linux - Software 3 01-27-2005 03:18 AM
/bin/mail command pk21 Linux - Software 3 11-16-2003 06:00 PM
linux command error message bash: /usr/bin/find: No such file or directory sundaram123 Linux - General 8 04-02-2002 07:18 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:45 AM.

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