Issue
I have a file bashrc
that creates a bunch of variables and references to programs that I don't usually want to have in my bash shell, so it's not part of my ~/.bashrc
file, and if I need them I can just source it source ~/path/bashrc
.
To not have to type the whole path because I use it with some frequency, I have a script in one of the directories in my $PATH
that contains just a couple of lines to source it
#!/bin/bash
source ~/path/bashrc
suppose the script if called extra-stuff
. I know that to run it without sourcing the file to a subshell I have to run it with a dot in front
. extra-stuff
Is there a way to have this happen without having to use the .
? So is there a way to source some extra part of what would normally be .bashrc by calling a script as you would call any other random binary file?
Solution
is there a way to source some extra part of what would normally be .bashrc by calling a script as you would call any other random binary file?
Not by calling a script. But you can call a function instead. In your ~/.bashrc
write
extrastuff() {
source path/to/optional/rc/file
}
or even leaven out the optional rc file by directly writing everything into the function:
extrastuff() {
# do stuff just as you would do in path/to/optional/rc/file
# only if you use declare/typeset, you have to add the -g option
}
Then, inside your interactive terminal session, type extrastuff
to execute that function.
Answered By - Socowi