我有一个如下所示的脚本:
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
beingtrue
或make之间的唯一区别false
是pipe_command_b
可能无法运行。有没有办法折叠它,这样我就不必重复所有常见的事情?
答案1
如果您想跳过它,请使用cat
而不是命令:
command=cat
if [[ $flag == true ]] ; then
command=pipe_command_b
fi
command \
| pipe_command_a \
| $command \
| pipe_command_c