Repository navigation
[Fix] install.sh shouldn't use not existed variable - #1605
Conversation
| BASH_OR_ZSH=false | ||
|
|
||
| if [ -z "${NVM_PROFILE-}" ] ; then | ||
| echo "=> Profile not found. Tried ${NVM_PROFILE} (as defined in \$PROFILE), ~/.bashrc, ~/.bash_profile, ~/.zshrc, and ~/.profile." |
There was a problem hiding this comment.
hmm, couldn't $PROFILE define a file that doesn't exist?
There was a problem hiding this comment.
I just move it to the end of the sentence, didn't remove it, would that be good?
The commit message was wrong, the point here is the installation script use not defined ${NVM_PROFILE} :)
There was a problem hiding this comment.
Totally, but it seems like NVM_PROFILE will only be undefined some of the time; which means that some of the time, displaying it is very helpful.
There was a problem hiding this comment.
hmmmm ... I don't understand, there is a line if [ -z "${NVM_PROFILE-}" ] ; then before, doesn't that mean it's always not defined in this code block?
There was a problem hiding this comment.
Right - $NVM_PROFILE will of course always be empty in this block; but the purpose of the message is to indicate the exact value the user had defined in their profile file. nvm_detect_profile looks at $PROFILE - I assume that's the original purpose of this message?
There was a problem hiding this comment.
I'm not very sure, so is this message going to tell the users it has tried ${NVM_PROFILE} this variable? Or just tell them that it has tried the following files?
There was a problem hiding this comment.
I think that if a profile file defines $PROFILE, but the -f check fails, then the error message should display the value of $PROFILE and indicate that it doesn't exist.
1fc41a8 to
bddfe6e
Compare
|
@ljharb I think I improved it with success, please take a look, thanks. |
| fi | ||
| echo "=> Profile not found. Tried ${TRIED_PROFILE-} ~/.bashrc, ~/.bash_profile, ~/.zshrc, and ~/.profile." | ||
| echo "=> Create one of them and run this script again" | ||
| echo "=> Create it (touch ${NVM_PROFILE}) and run this script again" |
There was a problem hiding this comment.
This line seems to be duplicated, I guess we can simply remove it.
| if [ -z "${NVM_PROFILE-}" ] ; then | ||
| echo "=> Profile not found. Tried ${NVM_PROFILE} (as defined in \$PROFILE), ~/.bashrc, ~/.bash_profile, ~/.zshrc, and ~/.profile." | ||
| if [ -n "${PROFILE}" ]; then | ||
| local TRIED_PROFILE |
There was a problem hiding this comment.
doesn't this local have to appear outside the if, if it's referenced outside it?
There was a problem hiding this comment.
I think it's still in the same function?
There was a problem hiding this comment.
For clarity, even if it's not required, it'd be nice to declare the var at a high enough scope to eclipse all uses.
There was a problem hiding this comment.
So would moving it to above current line 333 be okay?
| local TRIED_PROFILE | ||
| TRIED_PROFILE="${NVM_PROFILE} (as defined in \$PROFILE), " | ||
| fi | ||
| echo "=> Profile not found. Tried ${TRIED_PROFILE-} ~/.bashrc, ~/.bash_profile, ~/.zshrc, and ~/.profile." |
There was a problem hiding this comment.
This seems like it adds an extra space after TRIED_PROFILE?
bddfe6e to
74e6283
Compare
|
All fixed @ljharb |
| if [ -n "${PROFILE}" ]; then | ||
| TRIED_PROFILE="${NVM_PROFILE} (as defined in \$PROFILE)," | ||
| fi | ||
| echo "=> Profile not found. Tried ${TRIED_PROFILE-} ~/.bashrc, ~/.bash_profile, ~/.zshrc, and ~/.profile." |
There was a problem hiding this comment.
When TRIED_PROFILE is empty, this will be Tried ~/.bashrc - note the double space. iow, I think the space should go on line 335, and here, there should be no space after ${TRIED_PROFILE-}.
There was a problem hiding this comment.
hmmmm ... Just thought about the code readability so I did this, I can tweak it.
74e6283 to
a461a0f
Compare
[Fix] install.sh shouldn't use not existed variable
…profile detection - Use `=` instead of `==` for string comparison (POSIX compliance) - Use `printf '%b'` instead of variable as format string (prevents `%` characters in paths from being interpreted as format specifiers) - Fix `TRIED_PROFILE` to reference `PROFILE` instead of `NVM_PROFILE` which is known to be empty at that point Bugs introduced in a24ff3e, b6f1c15, and a461a0f (PR #1605).
Original codes will print like: