Creating a file with ed and a here document 0 ▲ Open source software and nice hardware 46 days ago · Tech · hide · Fediverse post Creating a file with ed and a here document When it comes to creating a new file with ed and a here document, there is a difference between "GNU ed" and "ed" on BSD. This is about creating a file, so we want to edit a file that not yet exists. Creating a file with GNU ed and a here document As an example we create the file /tmp/nofile: #!/bin/sh ed -s /tmp/nofile << EOF a one two three . w EOF This creates the file /tmp/nofile with the contents: one two three Creating a file with ed on BSD with a here document: The script above fails, because /tmp/nofile does not exists. However, this will work: #!/bin/sh ed -s << EOF a one two three . w /tmp/nofile EOF By not mentioning a non-existent file in the ed command, and naming it at the w command, it will work. This method works with GNU ed too, so this is the most portable way to create files with ed and a here document. Happy ed-ing! Commenting on Bubbles has been removed. Why? If you want to talk about this post, write to the author, use the comments on their blog if it has them, or reply with a "RE:" post on your own blog. Suggestions? feedback@bubbles.town