Skip to content

How to create and write a file with EOF in Bash

homepage-banner

Introduction

In Bash, one can create and write to a file using the echo command. However, this method has some limitations when it comes to writing multiple lines of text. One way to overcome this limitation is by using the EOF (End Of File) command. In this blog post, we will discuss how to create and write to a file using the EOF command in Bash.

Create and write a file with EOF in sh

cat << EOF > target.file
text file
EOF

append text to a file

cat << EOF >> target.file
append text
EOF

Conclusion

The EOF command is a useful tool for creating and modifying files with multiple lines of text in Bash. It allows you to write multiple lines of text without having to use the echo command repeatedly. By using the EOF command, you can save time and make your shell scripts more efficient.

Leave a message