A nice little shell trick:
You are all probably familiar with "here documents":
This will consider the lines of text from the standard input as input for cat. It is terminated by the special marker that comes after the '<<'. This is handy, for instance, to create text files:
cat <<THEEND >newfile
$variables will be expanded
I needed to write an internal document in my company. In it there were instructions for creating a certain configuration file. I wanted to be as user-friendly as possible. I initially wrote just the content of the file and its full path. But later wanted to improve the instructions. Thus wanted to use 'here documents'. But what if the users know their way already (and may have better ideas on the file name, etc.), how do I avoid getting in the way?
The first step is obvious. That file has '#'
as a comment marker. Thus I wrote:
# cat <<EOF >/the/full/path
Note the last empty line. When giving instructions to copy and paste to a terminal, you should leave a final empty line for the final press of Enter.
If someone accidentally copies the first line as well, it is still a valid configuration file. But then I thought: Why not make the marker a comment line as well?
# cat <<'#EOF'