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,570 points
89 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,370 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
98 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
• 68,880 points
158 views
0 votes
1 answer

How to take input from user in bash script?

You can use if-else branch to check ...READ MORE

answered Jan 31, 2019 in Linux Administration by Omkar
• 68,880 points
63 views
0 votes
1 answer

How to create a symlink in Linux?

To create a symbolic link, you can ...READ MORE

answered Jan 31, 2019 in Linux Administration by Omkar
• 68,880 points
87 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,510 points
52 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,370 points
42 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,370 points
262 views