echo multiple lines


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers echo multiple lines
# 1  
Old 03-24-2010
echo multiple lines

I have a code:
Code:
echo "First Line ^M  Second Line" | mail -s "Lines" abc@gmail.com

Basically, I want to send an email with text in this format:
Code:
First Line
Second Line

But there is something wrong with my 'echo'. The ^M is not interpreted as carriage return. Please help.
# 2  
Old 03-24-2010
What's the output of just:

Code:
echo "First Line ^M  Second Line"

# 3  
Old 03-24-2010
Actually what you probably want is
Code:
echo -e "First Line \n  Second Line"


Last edited by Yogesh Sawant; 03-24-2010 at 10:59 PM.. Reason: added code tags
# 4  
Old 03-24-2010
or...

Code:
#  mail -s "Lines" abc@def.com <<EOF
First Line
Second Line
EOF

# 5  
Old 03-24-2010
Or with "ksh":

Code:
(
echo "First Line"
echo "Second Line"
) | mail -s "Lines" abc@gmail.com


Tytalus solution is more portable.
# 6  
Old 03-24-2010
Thank you all!!!
# 7  
Old 03-24-2010
The ^M character is the carriage return. This is used alone in OS X or paired with a New Line character in Windows. Unix only uses the new line character, the code for which varies depending on how and where you use it. Another way to do it is to just type the line break within single quotes like this...

Code:
echo 'First line
Second Line'

You can then redirect or otherwise process this as you would any other output.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash Script: Echo continuation across many lines

I am writing a bash script that automatically generates a macro program. I want to have an echo on multiple lines and getting an error /home/chaos/instru-correct.sh: line 309: command line is: command not found I am using echo "# The general synopsis of the $mfl" \ ... (2 Replies)
Discussion started by: kristinu
2 Replies

2. Shell Programming and Scripting

Removing multiple lines from input file, if multiple lines match a pattern.

GM, I have an issue at work, which requires a simple solution. But, after multiple attempts, I have not been able to hit on the code needed. I am assuming that sed, awk or even perl could do what I need. I have an application that adds extra blank page feeds, for multiple reports, when... (7 Replies)
Discussion started by: jxfish2
7 Replies

3. Shell Programming and Scripting

multiple echo statements in if condition

Hi , I have a peculiar problem. i have an if block like this if ; then echo " todays date is " ${date} >> log_file echo " file count is " $ count >> log_file mv filename1 filename 2 else echo "no files available ">> log_file fi the echo statement "no files available " is not... (2 Replies)
Discussion started by: wizardofoz
2 Replies

4. Shell Programming and Scripting

echo multiple variable with calculation

$total=500 echo "scale=2; $val1*100/$total" | bc echo "scale=2; $val2*100*100/$total" | bc echo "scale=2; $val3*100/$total" | bc I want to make the above code to be accomplish in a single echo line. For instance output:21.3, 44.2, 51.6 How to achieve that, some one please help, i just... (5 Replies)
Discussion started by: alvin0618
5 Replies

5. Shell Programming and Scripting

Echo - Sending mail to multiple addresses

Hi, If I want my script to send a mail to multiple recipients I can do the following: if then echo $err_string1 | mailx -s "UAT CPU ALERT" 1@email.com echo $err_string1 | mailx -s "UAT CPU ALERT" 2@email.com fi Can this also be done something like: ... (1 Reply)
Discussion started by: runnerpaul
1 Replies

6. Shell Programming and Scripting

echo on several lines

Hi there, I managed to write a script that display its progress like this: ~# cat myscript echo -en ' Completed\015' for (( i=0; i<=100; i++ )) do echo -ne $i'%\015' # perform some actions sleep .01 done echo ~# myscript 100% Completed ~#I can't show it on this post, but... (2 Replies)
Discussion started by: chebarbudo
2 Replies

7. Shell Programming and Scripting

How to write multiple echo statements in unix?

How to write multiple echo statements in unix? echo "************************************************************************************************************"; echo This Script do the following functions echo 1. Point 1 echo 2. Point 2 echo 3. Point 3 echo... (2 Replies)
Discussion started by: Shrutiduggal
2 Replies

8. Shell Programming and Scripting

echo a block of lines

echo "line 1" echo "line 2" echo "..." echo "..." echo "line n-1" echo "line n" How can I echo n number of lines with one 'echo' command? (3 Replies)
Discussion started by: girisha
3 Replies

9. Shell Programming and Scripting

Nested Loop to Echo Multiple Arrays

I have three arrays which hold three elements each. I have a fourth array which contains the names of those three arrays. I'm having difficulty creating a nested loop that can loop through each array and echo their values. script #!/bin/ksh # array of locations (usa, london, australia)... (1 Reply)
Discussion started by: yongho
1 Replies

10. UNIX for Dummies Questions & Answers

combine 2 lines (command & echo)

does anyone know how to combine 2 lines? this is what im playing around with. (filename: online, user name: prml0001, real name: primal) #!/bin/sh who | grep $1 > /dev/null if then grep $1 /etc/passwd | cut -f 5, -d : echo is logged on exit 0 else grep $1... (13 Replies)
Discussion started by: primal
13 Replies
Login or Register to Ask a Question