I'm trying to get su
to source /home/ghost/.bashrc
, but it doesn't seem to load the contents:
$ su -l -c 'source /home/ghost/.bashrc; nvm' ghost
-su: nvm: command not found
I use nvm to manage Node versions. Nvm is normally sourced by the ghost
user in /home/ghost/.bashrc
:
# in /home/ghost/.bashrc
export NVM_DIR="/home/ghost/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
I found from these questsions that putting the nvm
init code in /home/ghost/.profile
makes nvm
available to su -l
since it starts a login shell.
I still can't figure out why I can't source
the file explicitly. Can anybody tell me why?
nvm.sh
, notnvm
. Also you don't need-l
:su -c 'source /home/ghost/.bashrc; nvm.sh' ghost
– kos Feb 06 '16 at 17:49nvm
. At least, that's what they suggest in their README. EIther way, that command doesn't work either unless I put thenvm
init stuff in~/.profile
. For some reason I can't source anything explicitly fromsu -c
. – beane Feb 06 '16 at 18:08nvm
means that the file is not being sourced? Where isnvm
, and does /home/ghost/.bashrc add that location to thePATH
? if so, how? – steeldriver Feb 06 '16 at 18:32"$NVM_DIR/nvm.sh"
was used to start it automatically. – kos Feb 06 '16 at 18:52ls -ld /home/ghost/.nvm/nvm.sh
– Cyrus Feb 06 '16 at 19:53echo
statements to the bashrc they also failed to print. I'll edit the question to add some more info. – beane Feb 06 '16 at 23:02/home/ghost/.bashrc
had code that halted execution if the shell wasn't being run in interactive mode. Starting from a blank.bashrc
or movingnvm
to the stop solved the problem. Thanks for all your help! – beane Feb 06 '16 at 23:10