Creating a file with ed and a here document 0 ▲ Open source software and nice hardware 1 hour ago · Tech · hide · 0 comments 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! No comments yet. Log in to reply on the Fediverse. Comments will appear here.