The following Bash code works:
text="SPECIAL"
COND=true
if [ "$COND" = true ]; then printf "${text}"; else : ; fi | cat bar.txt - foo.txt > ./output.txt
It uses the no-op colon operator.
Though, the pipe operator is being executed regardless of the condition.
I was wondering whether the pipe operator itself may be avoided - given a specific condition is true.
For example, I was hoping that something like this would work (it doesn't work as I want it to, rather it does something else):
text="SPECIAL"
COND=true
if [ "$COND" = true ]; then printf "${text}" | ; fi cat bar.txt - foo.txt > ./output.txt
Reason is - I want that the program which receives the pipe (i.e. cat in our example) wouldn't recognize any piping if some condition is true or false.
Meaning - the end result should be as follows:
If condition is true, then piping is enabled - as follows:
printf "${text}" | cat bar.txt - foo.txt > ./output.txt
If condition is false, then piping is disabled - as follows:
cat bar.txt - foo.txt > ./output.txt