Sunday, May 5, 2024
 Popular · Latest · Hot · Upcoming
5
rated 0 times [  5] [ 0]  / answers: 1 / hits: 497  / 2 Years ago, fri, november 11, 2022, 6:04:17

I have installed nvm and it was appended to my /home/www-data/.bashrc


Calling nvm works.


bash
nvm

works


but


$ bash -c nvm
bash: nvm: command not found

does not work.


same when I specific the rcfile


$ bash  --rcfile /home/www-data/.bashrc -c "nvm"
bash: nvm: command not found

Why is that?


In the end-result I want to use nvm in RoboFile exec() command and tried to wrap it into bash -c because nvm is a bash function and not a real script.


More From » bash

 Answers
7

Why is that?



When invoked with -c, bash runs as a non-interactive shell. The default interactive shell startup files (/etc/bash.bashrc, ~/.bashrc) are not read. Even if you force ~/.bashrc to be read, its body is likely not executed - the default Ubuntu one (copied from /etc/skel during account creation) for example includes the lines


# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac

which bypasses everything following.


You could force an interactive shell using bash -ic, however that may cause other issues depending on what else is in your .bashrc.


[#233] Sunday, November 13, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
freezidepu

Total Points: 394
Total Questions: 105
Total Answers: 118

Location: Libya
Member since Mon, Dec 7, 2020
3 Years ago
freezidepu questions
;