Issue
I have a script foo.sh
with some functions I'd like to test in a bash REPL, and for some reason I need to do this in a new bash REPL instead of sourcing it in the current shell, that is:
- Open up a new bash REPL
- Source
foo.sh
in the new-opened REPL
Is there such a way to do that in one command, like in python -i foo.py
or ghci foo.hs
? I have tried bash -i "foo.sh"
, bash -c "source foo.sh"
, bash -c "$(cat foo.sh)"
etc., but all of them seem to just execute the script and then immediately exit.
Solution
You can use process substitution to source both .bashrc and foo.sh :
bash --rcfile <(cat ~/.bashrc; cat foo.sh) -i
Answered By - Philippe Answer Checked By - Candace Johnson (WPSolving Volunteer)