Skip to content

Commit

Permalink
Fix "unbound variable" errors when set -u (#102)
Browse files Browse the repository at this point in the history
* Fix "unbound variable" errors when set -u

* Fix "unbound variable" errors when set -u
  • Loading branch information
rasa authored Aug 19, 2024
1 parent d5f3446 commit 088cca4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions internal/self/old_versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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`
Expand Down
8 changes: 4 additions & 4 deletions internal/shell/sh/zsh.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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
Expand Down Expand Up @@ -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 != "" {
Expand All @@ -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 {
Expand Down

0 comments on commit 088cca4

Please sign in to comment.