この質問にはすでに回答があります :条件付きパイプライン
(7つの回答)
3年前に閉鎖されました。
Linux
(7つの回答)
3年前に閉鎖されました。
次のようなスクリプトがあります:
flag=false
# Do a bunch of stuff that might set flag to true.
if [[ "$flag" == "true" ]]; then
command \
| pipe_command_a \
| pipe_command_b \
| pipe_command_c \
| pipe_command_d \
> "${output_path}"
else
command \
| pipe_command_a \
| pipe_command_c \
| pipe_command_d \
> "${output_path}"
fi
flag
の唯一の違い true
であること またはfalse
そのpipe_command_b
実行されない場合があります。これを折りたたんで、一般的なことをすべて繰り返す必要がないようにする方法はありますか?
承認された回答:
cat
を使用する スキップする場合は、コマンドの代わりに:
command=cat
if [[ $flag == true ]] ; then
command=pipe_command_b
fi
command \
| pipe_command_a \
| $command \
| pipe_command_c