I've got a script like the following:
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
The only difference between flag being true or false makes is that pipe_command_b may not be run. Is there a way to collapse this so that I don't have to repeat all of the common stuff?
lswhich you wouldn't want to use in a pipeline anyway butls | catprovides a different result than justls– jesse_b Aug 03 '17 at 17:50cat"changing some results". That'slsdetecting that its stdout is not a tty and producing different output (i.e. one filename per line rather than multiple filenames on multi-column line(s)). – cas Aug 04 '17 at 06:47