Skip to content

Instantly share code, notes, and snippets.

@tsibley
Last active June 9, 2023 17:38
Show Gist options
  • Save tsibley/6e4e5d4d023b9ec9663fa7707fa73655 to your computer and use it in GitHub Desktop.
Save tsibley/6e4e5d4d023b9ec9663fa7707fa73655 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Try different dirs each with the following contents to observe differences in
# implementations.
#
# file "abc" with contents "A\nB\nC\n"
# file "xyz" with contents "X\0Y\0Z\n"
# file "e" with contents "\nEEE\n"
# empty file "x=y"
# file "x=y" with contents "Z"
# empty directory "d"
# directory "d" with file "f"
# empty directory "d" when there's "d=1" in the calling environment already
#
declare -A envdirs=(
[daemontools]=/usr/bin/envdir # https://cr.yp.to/daemontools/envdir.html
[python]=~/.local/bin/envdir # https://pypi.org/project/envdir/
[tsibley]=~/bin/envdir # https://github.com/tsibley/envdir
)
envd="${1:?usage: envdir-compare <envd> [<cmd> [<args>…]]}"
shift
for impl in $(printf '%s\n' "${!envdirs[@]}" | sort); do (
envdir="${envdirs[$impl]}"
if [[ $# -gt 0 ]]; then
set -- "$envdir" "$envd" "$@"
else
set -- env --ignore-environment "$envdir" "$envd" perl -MJSON::PP -E 'say encode_json(\%ENV)'
fi
echo $'\e[1m'"[$impl] $@"$'\e[m'
"$@"
echo
); done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment