I'm doing this in a .sh
script which I'm calling like this sudo ./script.sh
:
user=${SUDO_USER} # ="alex"
sudo -su ${user} node
Result:
/bin/bash: node: command not found
Same goes for other commands like yarn
or nvm
also all are installed and working when being logged in as alex
What am I doing wrong?
which node
run as alex
returns this:
/home/alex/.nvm/versions/node/v10.15.1/bin/node
node
for alex
is installed using nvm
which adds this to the end of /home/alex/.zshrc
(alex
is using zsh
)
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
I think there is no user named node. try this
if it prints node, this works
if not create user named node, sth like this
and finally your scripts.sh will work.