Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Echo a large chunk of text to a file using Bash [duplicate]

Tags:

bash

I need to run a Bash script that can echo a 300 lines of Groovy script to a tmp file. What's the best way to do it ?

My current workaround is putting the script file online and download it.

like image 398
thinkanotherone Avatar asked Aug 01 '11 08:08

thinkanotherone


People also ask

How do I echo multiple lines in bash?

To add multiple lines to a file with echo, use the -e option and separate each line with \n. When you use the -e option, it tells echo to evaluate backslash characters such as \n for new line. If you cat the file, you will realize that each entry is added on a new line immediately after the existing content.

What is echo $$ in bash?

The echo command is used to display a line of text that is passed in as an argument. This is a bash command that is mostly used in shell scripts to output status to the screen or to a file.

How do I echo a line to a file?

Using '>>' with 'echo' command appends a line to a file. Another way is to use 'echo,' pipe(|), and 'tee' commands to add content to a file.


1 Answers

Use the heredoc syntax to embed the other script within a shell script:

cat > file.tmp <<'endmsg' script goes here... endmsg 
like image 113
Blagovest Buyukliev Avatar answered Oct 25 '22 02:10

Blagovest Buyukliev