diff options
author | Lars Wirzenius <liw@liw.fi> | 2020-10-11 09:25:15 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2020-10-11 09:25:15 +0300 |
commit | bc4462c604dac98cc9ef8b656baf8ce125941945 (patch) | |
tree | eb074ad6c74bc25d08c284991680df8b5f80aaf3 /templates | |
parent | 247a75fc4f5da908f92e384dbafec5dd8a6f599c (diff) | |
download | subplot-bc4462c604dac98cc9ef8b656baf8ce125941945.tar.gz |
refactor(templates/bash): unset environment variables without Python
Diffstat (limited to 'templates')
-rw-r--r-- | templates/bash/template.sh | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/templates/bash/template.sh b/templates/bash/template.sh index 04af08f..8e8d75a 100644 --- a/templates/bash/template.sh +++ b/templates/bash/template.sh @@ -236,8 +236,16 @@ scenario_{{ loop.index }}() { ############################################################################# # Make the environment minimal. -# unset all environment variables -unset $(python3 -c 'import os; print("".join(x + "\n" for x in os.environ.keys()))') +# Write to stdout the names of all environment variables, one per +# line. Handle also cases where the value of an environment variable +# contains newlines. +envnames() +{ + env -0 | xargs -0 -n1 -i'{}' sh -c "printf '%s\n' '{}' | head -n1 | sed 's/=.*//'" +} + +# unset all environment variables. +unset $(envnames) export PATH=/bin:/usr/bin export SHELL=/bin/sh export HOME=/ # Will be set to datadir for each scenario. |