Running command in new bash shell with --rcfile and -c
Solution 1:
By default, non-interactive bash
executions do not load initialization files, such as .bashrc
or the target of your --rcfile
option. As described in the man
page:
An interactive shell is one started without non-option arguments and without
the -c option whose standard input and error are both connected to terminals
... or one started with the -i option.
So you can get the behavior you want by forcing bash
to act like an interactive shell with -i
:
bash --rcfile .mybashrc -ci 'echo $FOO'