Echo multi-line string via heredoc syntax


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Echo multi-line string via heredoc syntax
# 1  
Old 06-23-2014
Echo multi-line string via heredoc syntax

Code:
[user@freegtw ~]$ cat bashtest
#!/usr/local/bin/bash
echo <<<"EOF"
line1
line2
line3
EOF

[user@freegtw ~]$ ./bashtest

./bashtest: line 3: line1: command not found
./bashtest: line 4: line2: command not found
./bashtest: line 5: line3: command not found
./bashtest: line 6: EOF: command not found

What am i doing wrong?
# 2  
Old 06-23-2014
Either
Code:
cat <<"EOF"
line1
line2
line3
EOF

Or, much more efficient
Code:
echo "\
line1
line2
line3"

# 3  
Old 06-23-2014
The same
Code:
[user@freegtw ~]$ cat bashtest
#!/usr/local/bin/bash
cat <<<"EOF"
line1
line2
line3
EOF

[user@freegtw ~]$ ./bashtest
EOF
./bashtest: line 3: line1: command not found
./bashtest: line 4: line2: command not found
./bashtest: line 5: line3: command not found
./bashtest: line 6: EOF: command not found

OS: FreeBSD 9.1
# 4  
Old 06-23-2014
<<< has a rather different meaning to bash -- it redirects a single line.

You should be doing <<, not <<<.
# 5  
Old 06-23-2014
Nice one, Corona! Thx.
This User Gave Thanks to urello For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Multi line log files to single line format

I want to read the log file which was generate from other command . And the output was having multi line in log files for job name and server name. But i need to make all the logs on one line Source file 07/15/2018 17:02:00 TRANSLOG_1700 Server0005_SQL ... (2 Replies)
Discussion started by: ranjancom2000
2 Replies

2. Shell Programming and Scripting

Help with reformat single-line multi-fasta into multi-line multi-fasta

Input File: >Seq1 ASDADAFASFASFADGSDGFSDFSDFSDFSDFSDFSDFSDFSDFSDFSDFSD >Seq2 SDASDAQEQWEQeqAdfaasd >Seq3 ASDSALGHIUDFJANCAGPATHLACJHPAUTYNJKG ...... Desired Output File >Seq1 ASDADAFASF ASFADGSDGF SDFSDFSDFS DFSDFSDFSD FSDFSDFSDF SD >Seq2 (4 Replies)
Discussion started by: patrick87
4 Replies

3. Shell Programming and Scripting

tcsh - understanding difference between "echo string" and "echo string > /dev/stdout"

I came across and unexpected behavior with redirections in tcsh. I know, csh is not best for redirections, but I'd like to understand what is happening here. I have following script (called out_to_streams.csh): #!/bin/tcsh -f echo Redirected to STDOUT > /dev/stdout echo Redirected to... (2 Replies)
Discussion started by: marcink
2 Replies

4. Shell Programming and Scripting

Multi-line filtering based on multi-line pattern in a file

I have a file with data records separated by multiple equals signs, as below. ========== RECORD 1 ========== RECORD 2 DATA LINE ========== RECORD 3 ========== RECORD 4 DATA LINE ========== RECORD 5 DATA LINE ========== I need to filter out all data from this file where the... (2 Replies)
Discussion started by: Finja
2 Replies

5. Shell Programming and Scripting

SH script to parse string and return multi-line file

Hello all, I have been asked to exercise my shell scripting and it has been 10 plus years since I used to do it so I can not remember hardly anything and ask for your help. What I need to do is copy a line out of a file that can be 10 to 100 characters long, I then need to parse this line into... (3 Replies)
Discussion started by: Alivadoro
3 Replies

6. Shell Programming and Scripting

File Reading for a certain string and echo the line before

Hi Guys, I have a big file like this. It has cache group line ( the bold lines ) and then followed by 10 status lines showing either Compelte or Failed. This pattern repeats several time. We can assume all the status lines have either Complete or Failed status for that Cache Group line. I... (13 Replies)
Discussion started by: MKNENI
13 Replies

7. Shell Programming and Scripting

Joining multi-line output to a single line in a group

Hi, My Oracle query is returing below o/p ---------------------------------------------------------- Ins trnas value a lkp1 x a lkp1 y b lkp1 a b lkp2 x b lkp2 y ... (7 Replies)
Discussion started by: gvk25
7 Replies

8. Shell Programming and Scripting

Multi line document to single lines based on occurance of string

Hi Guys, I am new to awk and sed, i am working multiline document, i want to make make that document into SINGLE lines based on occurace of string "dwh". here's the sample of my problem.. dwh123 2563 4562 4236 1236 78956 12394 4552 dwh192 2656 46536 231326 65652 6565 23262 16625623... (5 Replies)
Discussion started by: victor369
5 Replies

9. Shell Programming and Scripting

sed - multi-line regex syntax eval puzzle

sed novice bashing away at this.... I am trying to build a sed script that will find the instances of "cn" that have more than one "DirXML" value on them.... see sample below: I am not having any luck with any variation that tries to find "DirXML.*\nDirXML.*". Isn't there a way to get sed to... (6 Replies)
Discussion started by: gosleddog
6 Replies

10. IP Networking

Multi-client echo server

Hello I am currently learning how to program a multi-client server. I still have some code to configure, however I think I am fairly near to the end. My main problem is that whenever I connect with one client and receive an echo, do the same with another client and receive an echo, then try... (0 Replies)
Discussion started by: slanj
0 Replies
Login or Register to Ask a Question