多くのスイッチが必要な長いコマンドを呼び出すときは、シェルスクリプトで書くのが最善です。そのようなスクリプトで行をコメントアウトする簡単な方法はありますか?私は次のことを試しましたが、そのうちの何も動作しません。
# the \ is also commented out, resulting in "command" and "--good-switch".
command \
#--bad-switch \
--good-switch \
# seems to send an extra argument to the command
command \
\ #--bad-switch \
--good-switch
ベストアンサー1
これはオプションです。コマンドと引数を配列に保存して実行します。
# build the command
cmd=( ls
-F
# -a # comment out this option temporarily
-l
)
# $cmd is now an array with 3 elements
# execute it
"${cmd[@]}"