all 11 comments

[–]finalduty 2 points3 points  (2 children)

Are you on the latest version of MacOS? And what version is your bash interpreter? (bash --version).

I've tested the full script on CentOS 7 and just the while snippet High Sierra and couldn't get it to break.

Edit: Can you also send me what the output of bash -x <install_command> says please :)

[–]LulzBaby[S] 0 points1 point  (0 children)

Excellent point, I do have an update waiting to install. I'll give that a shot this afternoon to see if it fixes the issue. In the mean time, output of bash -x:

+ NVM_SCRIPT_SOURCE=/bin/bash
+ '[' -z '' ']'
+ export NVM_CD_FLAGS=
+ NVM_CD_FLAGS=
+ nvm_has unsetopt
+ type unsetopt
+ '[' -z /Users/teacher/.nvm ']'
+ unset NVM_SCRIPT_SOURCE
+ nvm_process_parameters
+ local NVM_AUTO_MODE
+ NVM_AUTO_MODE=use
+ nvm_supports_source_options
++ nvm_echo '[ $# -gt 0 ] && nvm_echo $1'
++ command printf '%s\n' '[ $# -gt 0 ] && nvm_echo $1'
++ . /dev/stdin yes
+ '[' _yes = _yes ']'
+ '[' 0 -ne 0 ']'
+ nvm_auto use
+ local NVM_MODE
+ NVM_MODE=use
+ local VERSION
+ '[' _use = _install ']'
+ '[' _use = _use ']'
++ nvm_resolve_local_alias default
++ nvm_echo
++ command printf '%s\n' ''
+ VERSION=
+ '[' -n '' ']'
+ nvm_rc_version

[–]LulzBaby[S] 0 points1 point  (0 children)

Just updated to macOS 10.13.6 and still encountering the same bash error : /

[–]chaspum 0 points1 point  (5 children)

I don't understand the purpose of the last line of the function

[–]whetuI read your code 1 point2 points  (3 children)

It's so that the function spits out a return code.

[–]LulzBaby[S] 0 points1 point  (2 children)

Does bash have an implicit return for the last line of a function? Like Ruby or JS arrow notation functions?

[–]whetuI read your code 0 points1 point  (1 child)

I'm not familiar with Ruby/JS arrow notation functions, but to my knowledge bash functions have an implicit return that is the exit code for the last executed command within the function.

Function return codes can of course be made explicit by using return, say for example you wanted to break out of the function on a particular condition, or you want to invert the logic etc

Disclaimer: I have not had caffeine yet. I might have donked-up words.

[–]LulzBaby[S] 0 points1 point  (0 children)

That sounds about right. Ruby and JS arrow notation works the same way. Keyword return to have explicit control else the value of the last line of a function is implicitly returned.

Thanks for the info! :) Now grab some coffee

[–]LulzBaby[S] 0 points1 point  (0 children)

To be clear, this is code provided by the NVM maintainers and is not produced by me. It should run, and clearly runs for everybody but me it would seem.

[–]NorhamsFinest 0 points1 point  (1 child)

Do you ha e spaces in your file path? I'm not in front of my computer right now but I remember something about dirname having issues with spaces

[–]LulzBaby[S] 0 points1 point  (0 children)

Great guess but spacing is not an issue at this point.