I'd like to print a man style usage message to describe a shell function like this output man find:
NAME find - search for files in a directory hierarchy SYNOPSIS find [-H] [-L] [-P] [-D debugopts] [-Olevel] [starting-point...] [expression] DESCRIPTION This manual page documents the GNU version of find. GNU find searches the directory tree rooted at each given starting-point by evaluating the given expression from left to right, according to the rules of precedence (see section OPERATORS), until the outcome is known (the left hand side is false for and opera‐ tions, true for or), at which point find moves on to the next file name. If no starting-point is speci‐ fied, `.' is assumed. OPTIONS I am facing an error message on the ` character.
Following simple script shows the error:
~$ cat <<EOF `.' EOF bash: bad substitution: no closing "`" in `.' I though heredoc was a cool way to echo strings by pasting them without having to escape its content such a quotes, etc... I assume I was wrong :/
Can someone explain this behavior please? Can heredoc accept ` character?
Edit 2: I accepted the answer of quoted here-document <<'END_HELP', but I finally won't use it for this kind of complete manual output as kusalananda does suggests
Edit 1: (For future reads) the limit with using quoted here-document is that is prevents to use tput in the here-document.
To do so, I did the following:
- unquoted
here-document, fortputcommands to be executed - prevent the "bad substitution" error by escaping the backtick instead
- use
tputwithin thehere-document
Example:
normal=$( tput sgr0 ) ; bold=$(tput bold) ; cat <<END_HELP # here-document not quoted ${bold}NAME${normal} find - search for files in a directory hierarchy ${bold}SYNOPSIS${normal} find [-H] [-L] [-P] [-D debugopts] [-Olevel] [starting-point...] [expression] ${bold}DESCRIPTION${normal} This manual page documents the GNU version of find. GNU find searches the directory tree rooted at each given starting-point by evaluating the given expression from left to right, according to the rules of precedence (see section OPERATORS), until the outcome is known (the left hand side is false for and opera‐ tions, true for or), at which point find moves on to the next file name. If no starting-point is speci‐ fied, \`.' is assumed. END_HELP unset normal ; unset bold ; Here, note the escaped backtick that was source of error:
\`.' 
EOFand it'll work.