Skip to content

Instantly share code, notes, and snippets.

@AlexRogalskiy
Created February 27, 2022 12:25
Show Gist options
  • Save AlexRogalskiy/ff2046f0512bac1ccb6a296a88a2dd28 to your computer and use it in GitHub Desktop.
Save AlexRogalskiy/ff2046f0512bac1ccb6a296a88a2dd28 to your computer and use it in GitHub Desktop.
Compare the execution environment of numerous shells, both sourced and running a script.
#!/bin/sh
# creates env.{source|run}.SHELL, diff them for details for details.
# It is not fancy.
# Usage: compare_shells
for MY_SHELL in zsh rbash bash sh tcsh csh ksh dash; do
THE_SHELL=`which $MY_SHELL 2>/dev/null`
if [ -x "$THE_SHELL" ]; then
echo "$THE_SHELL"
echo "$THE_SHELL" | grep 'cs' >/dev/null && SRC='source' || SRC='.'
cat << EOF > runner.tmp
#!$THE_SHELL
$SRC ./subrunner.tmp | sort -u > 'env.source.$MY_SHELL'
"$THE_SHELL" ./subrunner.tmp | sort -u > 'env.run.$MY_SHELL'
EOF
cat << EOF > subrunner.tmp
#!$THE_SHELL
set
env
printenv
EOF
chmod +x runner.tmp subrunner.tmp
./runner.tmp
fi
done
rm -f runner.tmp subrunner.tmp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment