I try to run nvm
as a different user from a bash script. It is installed already and the NVM_DIR
environment variable is set in /home/user/.bashrc
:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
Using plain su
works:
root@ubuntu:~# su user
user@:/root$ echo $NVM_DIR
/home/user/.nvm
Trying the same thing with su -c
does not work though:
root@ubuntu:~# su user -c 'echo $NVM_DIR'
root@ubuntu:~#
How can I use environment variables with su -c
?
user
's bashrc