The easiest way (if possible) would be to avoid string ops, set a flag like error=0; do
output=$(thecommand --options $item 2>&1); and use the exit value, like error=$?.
[ $error -ge 0 ] && { echo you have a problem with this host; so you can skip the rest; }
If you need to use the output then you could echo "$output"|grep -q 'No.route' && error=1
or case "$output" in *route*) error=1;; esac to set a flag. So based on [ $error -eq 0 ] you
know if you want to && echo "$machine $output".
Code:
#!/bin/bash
LIST=$(cshosts publinux); for ITEM in $LIST; do
ERROR=0; OUTPUT=$($CMD --options $ITEM 2>&1)
ERROR=$?; [ $ERROR -eq 0 ] && echo "${ITEM}: \
${OUTPUT}"; done; exit 0