in linux

Cat Multiple Lines of Text to a file from bash script

You may find yourself needing to echo out multiple lines to the console, or even to another file, then you’ll want to use the following method which is much cleaner and much more efficient.

It’s very useful in creating another document, script, or file without having to use echo for each line.

 

cat > new_filename <<EOL
This is a test
This is a test
This is a test
This is a test
This is a test
EOL

 

You may also put variables to the multiline string.

Cat multiline string with variable expansion

variable1="ONE"
variable2="TWO"
variable3="THREE"
 
cat > myfile.txt <<EOF
this file has 3 variables
$variable1
$variable2
$variable3
EOF