無効な代替: 区切り文書/EOF で「`」で終わらない。

無効な代替: 区切り文書/EOF で「`」で終わらない。

男性スタイル活用情報次の出力を記述するシェル関数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

`文字にエラーメッセージが表示されます。
次の簡単なスクリプトはエラーを示しています。

~$ cat <<EOF
`.'
EOF

bash: bad substitution: no closing "`" in `.'

heredoc文字列を貼り付けてエコーするのが素晴らしい方法だと思いました。引用符などの内容をエスケープする必要はありません。 私が間違っていると思います:/

誰かがこの動作を説明できますか? `文字は許可されていますかheredoc

編集2:答えを受け入れました。ここで引用した文書 <<'END_HELP'しかし、この種の完全な手動出力には使用しません。先行する提案

編集1:(後で読めるように)使用制限ここで引用した文書tputで使用がブロックされましたhere-document
そのために、私は次のことをしました。

  1. 引用符なしでコマンドが実行されるときにhere-document使用されます。tput
  2. バックティックをエスケープして、「誤った置換」エラーを回避します。
  3. tput内部用here-document

例:

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 ;

ここでエラーの原因としてエスケープされたバックティックを記録してください。

\`.'

ベストアンサー1

バックティックはコマンド置換を導入します。ここにあるドキュメントは参照されないため、これはシェルで解釈されます。コマンド置換に終了バックティックがないため、シェルは文句を言います。

この記事を引用するには、次のようにします。

cat <<'END_HELP'
something something help
END_HELP

または

cat <<\END_HELP
something something help
END_HELP

この問題を解決するためのあなたのコメントに関して:

ユーティリティは完全なマニュアル自体を出力することはほとんどありませんが、要約情報または基​​本使用情報を提供できます。色が指定されることはほとんどありません(たとえば、出力が端末またはポケットベルに渡されない可能性があるためless)。実際のマニュアルは通常、groff専用のマニュアルページフォーマッタを使用してフォーマットされます。mandocそしてコードとは完全に別々に扱われます。

おすすめ記事