diff options
author | Richard Maw <richard.maw@gmail.com> | 2021-08-05 19:17:40 +0100 |
---|---|---|
committer | Richard Maw <richard.maw@gmail.com> | 2021-08-05 19:32:40 +0100 |
commit | 47a7b4532a0f7cfd8c0b7f258f53df5d9929d0ab (patch) | |
tree | a4df95081664ba80b4f2107cc9b5c330fe6bf5cb /share | |
parent | bad3f7cf29b0312c54df7e3df711b19cba57a26c (diff) | |
download | subplot-47a7b4532a0f7cfd8c0b7f258f53df5d9929d0ab.tar.gz |
bash: Support --env option in generated scripts
Diffstat (limited to 'share')
-rw-r--r-- | share/bash/template/template.sh.tera | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/share/bash/template/template.sh.tera b/share/bash/template/template.sh.tera index 938509a..0e67c4e 100644 --- a/share/bash/template/template.sh.tera +++ b/share/bash/template/template.sh.tera @@ -2,6 +2,40 @@ set -eu -o pipefail +declare -a ENV + +TEMP="$(getopt --long env: -o e: -- "$@")" +eval set -- "$TEMP" +unset TEMP + +while true +do + case "$1" in + '-e'|'--env') + case "$2" in + *=*) + # Use value from command-line + ENV=("${ENV[@]}" "$2") + ;; + *) + # Forward variable from environment + ENV=("${ENV[@]}" "$2=${!2}") + ;; + esac + shift 2 + continue + ;; + '--') + shift + break + ;; + *) + echo Unexpected argument >&2 + exit 1 + ;; + esac +done + ############################################################################# # Functions that implement steps. @@ -133,6 +167,11 @@ unset $(envnames) export PATH=/bin:/usr/bin export SHELL=/bin/sh +# Include any configured environment variables +for var in "${ENV[@]}" +do + export "$var" +done ############################################################################# # Run the scenarios. |