How to use a pipe in a script optionally How can I achieve the conditional usage of a pipe for a command execution in a script.

It looks like this

#!/bin/bash
XCPRETTY=" | xcpretty"
if [ $(which xcpretty | wc -l) == 0 ]; then
    XCPRETTY=""
fi
xcodebuild archive ....... $XCPRETTY || exit 1
Just use cat as a no-op if xcpretty is not installed:

XCPRETTY="xcpretty"
which xcpretty || XCPRETTY="cat"
xcodebuild archive ....... | eval $XCPRETTY || exit 1