Bash – How to load .bashrc from “bash -c”

bash

Trying to run a function defined in my .bashrc using "bash -c ". I end up with the error "command not found". How do I get "bash -c" to load my init file?

Best Answer

You can make it into an interactive shell with -i, then your ~/.bashrc will be read:

bash -i -c "echo \$EDITOR"

The other thing you can do is source the file explicit. If you have /var/tmp/test with content:

export XXX=123

and you do

bash -c "source /var/tmp/test; echo \$XXX"

you will get 123 echoed.

Related Question