From 9ba422e5615c4cf4f2571c91bb2b42e0970405d4 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 26 Jan 2026 22:33:58 -0800 Subject: [PATCH] [Fix] `nvm_strip_path`: avoid gawk-specific `RT` variable for mawk compatibility --- nvm.sh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/nvm.sh b/nvm.sh index effb506..58323c5 100755 --- a/nvm.sh +++ b/nvm.sh @@ -978,13 +978,18 @@ nvm_strip_path() { nvm_err '${NVM_DIR} not set!' return 1 fi - command printf %s "${1-}" | command awk -v NVM_DIR="${NVM_DIR}" -v RS=: ' + local RESULT + RESULT="$(command printf %s "${1-}" | command awk -v NVM_DIR="${NVM_DIR}" -v RS=: ' index($0, NVM_DIR) == 1 { path = substr($0, length(NVM_DIR) + 1) if (path ~ "^(/versions/[^/]*)?/[^/]*'"${2-}"'.*$") { next } } - # The final RT will contain a colon if the input has a trailing colon, or a null string otherwise - { printf "%s%s", sep, $0; sep=RS } END { printf "%s", RT }' + { printf "%s%s", sep, $0; sep=RS }')" + # mawk does not support RT, so preserve trailing colon manually + case "${1-}" in + *:) command printf '%s:' "${RESULT}" ;; + *) command printf '%s' "${RESULT}" ;; + esac } nvm_change_path() {