while read -r cmd; do
result=$( command $cmd 2>/dev/null || echo "Just a boring error" )
printf '%s\t- %s\n' "$cmd" "$result"
Read will read from the standard input of the shell, line by line. If you try to use
for cmd in $(cat), the
cat process will need to exit before any part of the loop is run. With the above loop, each iteration is done as the lines arrive on standard input.
result variable will get the output of the command substitution. The command substitution will return the output of the command, or the
echo if the command in
$cmd exited with a non-zero exit status.