Bash スクリプトで複数行のコマンドを記述する方法はわかっていますが、複数行のコマンドの各行にコメントを追加するにはどうすればよいでしょうか?
CommandName InputFiles \ # This is the comment for the 1st line
--option1 arg1 \ # This is the comment for the 2nd line
--option2 arg2 # This is the comment for the 3nd line
しかし残念ながら、継続文字の後のコメントは\
コマンドを壊してしまいます。
ベストアンサー1
これが私のやり方です。基本的にはBashのバックティックを使ってコマンド置換これらのコメントは、長いコマンド ラインのどこにでも配置できます (複数行に分割されている場合も含む)。例を実行して動作を確認できるように、例の前に echo コマンドを配置しました。
echo CommandName InputFiles `#1st comment` \
--option1 arg1 `#2nd comment` \
--option2 arg2 `#3rd comment`
1 行の異なるポイントに複数のコメントを配置できる別の例:
some_cmd --opt1 `#1st comment` --opt2 `#2nd comment` --opt3 `#3rd comment`