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?
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:
and you do
bash -c "source /var/tmp/test; echo \$XXX"
you will get
Another option would be to set the
When bash is started non-interactively, to run a shell script, for example, it looks for the variable BASH_ENV in the environment, expands its value if it appears there, and uses the expanded value as the name of a file to read and execute. Bash behaves as if the following com‐ mand were executed: if [ -n "$BASH_ENV" ]; then . "$BASH_ENV"; fi but the value of the PATH variable is not used to search for the file name.
So, you could do:
BASH_ENV=~/.bashrc && bash -c 'your_function'