From 088cca4ad47b51655c5d843b98597374b9c801b3 Mon Sep 17 00:00:00 2001 From: Ross Smith II Date: Sun, 18 Aug 2024 21:03:46 -0700 Subject: [PATCH] Fix "unbound variable" errors when set -u (#102) * Fix "unbound variable" errors when set -u * Fix "unbound variable" errors when set -u --- internal/self/old_versions.go | 6 +++--- internal/shell/sh/zsh.go | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/internal/self/old_versions.go b/internal/self/old_versions.go index 37628cb..d8f8de7 100644 --- a/internal/self/old_versions.go +++ b/internal/self/old_versions.go @@ -22,7 +22,7 @@ type OldConfig struct { } var OldShellRC string = `# vm_envs start -if [ -z $VM_DISABLE ]; then +if [ -z "${VM_DISABLE}" ]; then . ~/.vm/vmr.sh fi # vm_envs end` @@ -94,13 +94,13 @@ func DetectAndRemoveOldVersions() { var NewShellRC = ` # vm_envs start -if [ -z $VM_DISABLE ]; then +if [ -z "${VM_DISABLE}" ]; then . ~/.vmr/vmr.sh fi # vm_envs end` var NewShellRCFish = `# vm_envs start -if not test $VM_DISABLE +if not test "${VM_DISABLE}" . ~/.vmr/vmr.fish end # vm_envs end` diff --git a/internal/shell/sh/zsh.go b/internal/shell/sh/zsh.go index 295990a..16c01fa 100644 --- a/internal/shell/sh/zsh.go +++ b/internal/shell/sh/zsh.go @@ -17,7 +17,7 @@ In cdhook, it will cd to the target directory and then try to execute "vmr use - The command "vmr use -E" will automatically find the .vmr.lock file, and add corresponding versions of an SDK to the envs. */ const vmEnvZsh = `# cd hook start -export PATH=%s:$PATH +export PATH=%s:"${PATH}" if [ -z "$(alias|grep cdhook)" ]; then cdhook() { @@ -30,7 +30,7 @@ if [ -z "$(alias|grep cdhook)" ]; then alias cd='cdhook' fi -if [ ! $VMR_CD_INIT ]; then +if [ -z "${VMR_CD_INIT}" ]; then VMR_CD_INIT="vmr_cd_init" cd "$(pwd)" fi @@ -72,7 +72,7 @@ func (z *ZshShell) WriteVMEnvToShell() { // content, _ := os.ReadFile(vmEnvConfPath) // oldEnvStr := strings.TrimSpace(string(content)) envStr := fmt.Sprintf(vmEnvZsh, FormatPathString(installPath)) - vmrEnvPath := fmt.Sprintf("export PATH=%s:$PATH", FormatPathString(installPath)) + vmrEnvPath := fmt.Sprintf(`export PATH=%s:"${PATH}"`, FormatPathString(installPath)) UpdateVMRShellFile(vmEnvConfPath, vmrEnvPath, envStr) // if !strings.Contains(oldEnvStr, envStr) { // if oldEnvStr != "" { @@ -98,7 +98,7 @@ func (z *ZshShell) WriteVMEnvToShell() { } func (z *ZshShell) PackPath(path string) string { - return fmt.Sprintf("export PATH=%s:$PATH", path) + return fmt.Sprintf(`export PATH=%s:"${PATH}"`, path) } func (z *ZshShell) PackEnv(key, value string) string {