Arianna Arianna - 15 days ago 5
Linux Question

Gathering commands, defined in .bashrc, in different files

I'd like to gather the commands, defined in .bashrc, in different files like:

filePartOne:

commandOne1(){...}
commandOne2(){...}
...


filePartTwo:

commandTwo1(){...}
commandTwo2(){...}
...


and then "include" them with something like this in .bashrc:

"include"{filePartOne}
"include"{filePartTwo}
...


so I could use them as if they were in the .bashrc file.
Is it possible?

Answer

You can use the command source in your .bashrc file

Example if you have commandOne.sh and commandTwo.sh:

Your .bashrc

source commandOne.sh
source commandTwo.sh

It will execute the file in the same shell as the one your .bashrc was run in.