Trouble using nvm in any scripts

I installed nvm, as per the install instructions here, and it works fine if I type stuff in directly into the command line.

For example

sh:
$ nvm ls

And it runs fine. I understand that the nvm command works because of these couple of lines that are added to .profile:

sh:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm

But whenever running any script or trying to use the commands nohup, immortal, or dtach, it can't find the nvm command.

sh:
$ nohup nvm ls

sh:
nohup: nvm: No such file or directory

sh:
$ dtach -A /tmp/mk14 nvm install 14
dtach: could not execute nvm: No such file or directory

I'm new to FreeBSD (and loving it!), so maybe I don't understand how .profile works. Any ideas?
 
nvm is implemented using shell functions (set up with . $NVM_DIR/nvm.sh).

These functions work with Bourne-like shells (sh, ksh, zsh, bash,...).

nohup(1) applies to commands (executable files) and not to shell script functions (which seem like commands, but are not).

What you are trying to do will not work, but you could create a shell script wrapper (executable file) to get what you want, e.g.:
Code:
$ mkdir -p $HOME/bin
$ cd $HOME/bin
$ cat - >mynvm <<EOF
#!/bin/sh
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # Import the nvm functions
nvm $*
EOF
$ chmod 755 mynvm
$ export PATH="$PATH:$HOME/bin"
$ nohup mynvm ls
Make sure that $HOME/bin is added permanently to your PATH (edit $HOME/.profile. Also, set the PATH explicitly in the mynvm script to what you want.
 
Back
Top