0

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

filePartOne.sh:

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

filePartTwo.sh:

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

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

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

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

  • 1
    The build-in to load additional source files is called `source` or `.`. – ceving Nov 21 '16 at 13:11
  • 1
    [My own answer](http://stackoverflow.com/a/13588876/45249) to [Forward declarations in bash?](http://stackoverflow.com/q/13588457/45249) question might be a good starting point. – mouviciel Nov 21 '16 at 13:14

1 Answers1

3

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.

Kevin G.
  • 388
  • 1
  • 6
  • No, I'm looking for something else, look at my updated question – Arianna Angeletti Nov 21 '16 at 11:59
  • I'm not sure I understand what you want then. You'd like to have functions in several files and then insert them all in your .bashrc? – Kevin G. Nov 21 '16 at 12:20
  • 2
    The source command should do what you were asking for. When your .bashrc is executed, it will fetch commandOne.sh and execute it in the same shell you have run your .bashrc file in. The modifications added by your commandOne.sh should be visible and accessible from your .bashrc – Kevin G. Nov 21 '16 at 13:11
  • I tried your suggestion with: `source filePartOne.sh; source filePartTwo.sh;` and it worked! – Arianna Angeletti Nov 21 '16 at 15:59