Last active
February 24, 2017 15:14
-
-
Save kusalananda/1981b54a148db161ec166409ad22d599 to your computer and use it in GitHub Desktop.
Shell function that test a command in all installed shells and captures+displays the output. Should work with both ksh93 and bash.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function shtest | |
{ | |
# Will run the given command in all avaliable shells and capture and | |
# display the output generated on standard output as well as any | |
# diagnostic messages generated on standard error, together with the | |
# exit code. | |
grep '^[^#]' /etc/shells | ( | |
typeset -a tmpfiles | |
trap 'rm -f "${tmpfiles[@]}"' EXIT | |
while read realshell; do | |
typeset shell="${realshell##*/}" | |
typeset tmpout="$( mktemp -p /tmp "$shell-out.XXXXXXXX" )" | |
typeset tmperr="$( mktemp -p /tmp "$shell-err.XXXXXXXX" )" | |
tmpfiles+=( "$tmpout" "$tmperr" ) | |
command "$realshell" -c "$@" 1>"$tmpout" 2>"$tmperr" | |
err="$?" | |
printf '=== %s (exit %d)\n' "$shell" "$err" | |
echo "--- stdout:" | |
cat "$tmpout" | |
echo "--- stderr:" | |
cat "$tmperr" | |
done ) | |
} | |
# vim: ft=sh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment