github.com/canonical/ubuntu-image@v0.0.0-20240430122802-2202fe98b290/tests/lib/external/snapd-testing-tools/tools/quiet (about) 1 #!/bin/bash 2 3 # use "quiet foo" when you expect "foo" to produce a lot of output 4 # that isn't useful unless foo itself fails. 5 quiet() ( 6 # note this is a subshell (parens instead of braces around the function) 7 # so this set only affects this function and not the caller 8 { set +x; } >&/dev/null 9 10 # not strictly needed because it's a subshell, but good practice 11 local tf retval 12 13 tf="$(mktemp)" 14 15 set +e 16 "$@" >& "$tf" 17 retval=$? 18 set -e 19 20 if [ "$retval" != "0" ]; then 21 echo "quiet: $*" >&2 22 echo "quiet: exit status $retval. Output follows:" >&2 23 cat "$tf" >&2 24 echo "quiet: end of output." >&2 25 fi 26 27 rm -f -- "$tf" 28 29 return $retval 30 ) 31 32 quiet "$@"