From 27e3d4e177e83aac805bf93c38233fa1a9f06101 Mon Sep 17 00:00:00 2001 From: Rick Brown Date: Tue, 13 Dec 2022 03:20:27 +1100 Subject: [PATCH] Allow env.sh to accept additional env var names (#3339) The hard-coded list is not necessarily enough. This allows the caller to specify additional environment variables to write to .env. Co-authored-by: Konstantin Tyukalov <52399739+KonstantinTyukalov@users.noreply.github.com> Co-authored-by: Kirill Ivlev <102740624+kirill-ivlev@users.noreply.github.com> --- src/Misc/layoutroot/env.sh | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/Misc/layoutroot/env.sh b/src/Misc/layoutroot/env.sh index 0bf710038e..92b597f4f6 100755 --- a/src/Misc/layoutroot/env.sh +++ b/src/Misc/layoutroot/env.sh @@ -1,13 +1,13 @@ #!/bin/bash varCheckList=( - 'LANG' - 'JAVA_HOME' - 'ANT_HOME' - 'M2_HOME' - 'ANDROID_HOME' - 'GRADLE_HOME' - 'NVM_BIN' + 'LANG' + 'JAVA_HOME' + 'ANT_HOME' + 'M2_HOME' + 'ANDROID_HOME' + 'GRADLE_HOME' + 'NVM_BIN' 'NVM_PATH' 'VSTS_HTTP_PROXY' 'VSTS_HTTP_PROXY_USERNAME' @@ -17,6 +17,16 @@ varCheckList=( 'AGENT_TOOLSDIRECTORY' ) +# Allows the caller to specify additional vars on the commandline, for example: +# ./env.sh DOTNET_SYSTEM_GLOBALIZATION_INVARIANT DOTNET_ROOT +for arg in "$@" +do + if [[ ! " ${varCheckList[@]} " =~ " ${arg} " ]]; then + varCheckList+=($arg) + fi +done + + envContents="" if [ -f ".env" ]; then @@ -34,7 +44,7 @@ function writeVar() if [ ! -z "${!checkVar}" ]; then echo "${checkVar}=${!checkVar}">>.env fi - fi + fi } echo $PATH>.path