Consider the following command block:
if [[ ${EXTRA_PROCESS} -eq 1 ]]; then
producer | tee >(calc1 > ${out1}) >(calc2 > ${out2}) | consumer
else
producer | tee >(calc1 > ${out1}) | consumer
fi
This does what it's supposed to do. However, that's rather a lot of code repartition. So I changed it to look like this:
TEE="tee >(calc1 > ${out1})"
if [[ ${EXTRA_PROCESS} -eq 1 ]]; then
TEE="$TEE >(calc2 > ${out2})"
fi
producer | ${TEE} | consumer
That's much less code duplication. Unfortunately, the script is now completely broken. When I run it, it creates three giant files in the current directory:
blackbox:~ # ls
>
>(calc1
>(calc2
...
(I'm impressed that it's even possible to have files with those names in the first place... Deleting them was even more fun!)
Can somebody explain
- Why Bash is treating the strings literally rather than interpreting them?
- How I can force Bash to actually do what I asked for?