Writing a heredoc to a file in a script

0 votes

How can I write a here document to a file in a script?

May 20, 2019 in Linux Administration by Upasana
• 8,620 points
375 views

1 answer to this question.

0 votes

try to use tee:

tee newfile <<EOF
line 1
line 2
line 3
EOF

It's concise and can be combined with sudo if you need to write to files with root permissions.

answered May 20, 2019 by Shubham
• 13,450 points

Related Questions In Linux Administration

0 votes
1 answer

How do I use a shell script to SSH in to a remote machine to execute commands?

Your first problem can be solved like ...READ MORE

answered Jun 27, 2019 in Linux Administration by ajs3033
• 7,280 points
3,421 views
0 votes
1 answer

How to check permissions of a file in the Linux system?

Hi@akhtar, If you prefer using the command line, ...READ MORE

answered Aug 13 in Linux Administration by MD
• 66,980 points
114 views
0 votes
1 answer

How to find the first field from a file in Bash Shell?

Hi@akhtar, You can extract text from a file. ...READ MORE

answered Oct 19 in Linux Administration by MD
• 66,980 points
15 views
–1 vote
1 answer

How to get octal file permission in linux?

You can use this: stat -c "%a %n" ...READ MORE

answered Jan 3, 2019 in Linux Administration by Omkar
• 69,030 points
444 views
0 votes
1 answer
+1 vote
3 answers
0 votes
1 answer

Make a unix alias with python script

The scope of an alias command is the shell ...READ MORE

answered Sep 10, 2018 in Python by Priyaj
• 57,700 points
97 views
0 votes
1 answer

Script file name in a Bash script

$0 will give you the complete basename. ...READ MORE

answered Jun 20, 2019 in Linux Administration by Shubham
• 13,450 points
86 views
0 votes
1 answer

How to extract file base name without path and extension in bash?

You don't actually have to call the ...READ MORE

answered May 31, 2019 in Linux Administration by Shubham
• 13,450 points
2,230 views