I'm making this test script to help me reverse engineer scripts in charge of setting the dev environment.
The script:
#env-changes
#!/bin/bash
TESTED_SCRIPT=$1
shift
ENV_BEFORE=$(env | sort)
. $TESTED_SCRIPT
ENV_AFTER=$(env | sort)
diff <(printf '%s\n' "$ENV_BEFORE") <(printf '%s\n' "$ENV_AFTER")
Dummy env script:
#!/bin/bash
export I_AM_NEW=hello
Usage:
$ ./env-changes dummy-env-script.sh
21a22
> I_AM_NEW=hello
Currently it only works with bash. Suggestions on how to make it more POSIX compilant?
#!line should be the FIRST line of the script. If your first line is#env-changesas you've posted it, it is only being run bybashbecause/bin/shis the default interpreter and/bin/shisbashon your system. It's not uncommon even on linux systems for/bin/shto bedashorashor some other minimalist posix sh (partly because they're much smaller and often faster thanbash, and because some people see the huge size of bash as a potential security risk due to the larger "attack surface" of large programs vs small programs).