我想打印一条男子风格的使用消息来描述类似于这个输出man find的shell函数:
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我正面临‘字符’上的错误消息。下面的简单脚本显示了错误:
~$ cat <我认为heredoc是回显字符串的一种很好的方式,因为粘贴它们时,without必须转义它的内容,例如引号等等……我认为我错了:/ /
有人能解释一下这种行为吗?heredoc能接受‘字符’吗?
Edit 2:我在这里接受了quoted的答案-document <<'END_HELP',但我最终不会像[医]苦瓜 建议那样将它用于这种完整的手动输出
Edit 1:(对于将来的阅读)这里使用quoted的限制&document是防止在here-document中使用tput。为此,我做了以下工作:
未加引号的here-document,用于执行tput命令通过转义回勾来防止“坏替换”错误。在tput中使用here-document示例:
normal=$( tput sgr0 ) ;
bold=$(tput bold) ;
cat <在这里,注意转义的回勾,这是错误的来源:
\`.'发布于 2018-02-11 15:26:18
反勾号引入一个命令替换。由于这里的文档没有引用,这将由shell解释。shell会抱怨,因为命令替换没有结束反勾。
若要引用此处文档,请使用
cat <<'END_HELP'
something something help
END_HELP或
cat <<\END_HELP
something something help
END_HELP关于你对解决这一问题的评论:
实用程序很少单独输出完整的手册,但可能会提供概要或基本使用信息。这是很少,如果有,颜色(因为它的输出可能不是指向终端或寻呼机,如less)。真正的手册通常使用groff或像mandoc这样的专用手册格式化程序进行类型审查,并且与代码完全分开处理。
https://unix.stackexchange.com/questions/423392
复制相似问题