Sourcing from a different bashrc - linux

My original .bashrc script is currently used to run model runs. Now I need to manipulate it to compile a completely new model.
My question is, if I save my original .bashrc, as something such as .bwwbashrc, do I need to manipulate the file in some way so it is able to be read or recognized as the .bashrc when I source it within my scripts?
original sourcing
source /home/tsee/.bashrc
What I think the new sourcing would be.
(after creating .bwwbashrc)
source /home/tsee/.bwwbashrc
Just not sure if I need to save it with a certain extension or edit the executable in some sort of way.

Nope, you can name it whatever you want. Executable bit isn't required either.
If you aren't aware of it, the bash --login option might be of interest to you.

To complement Matt’s correct answer, I’d also point out that you can start a new Bash shell that sources your alternative file instead of .bashrc at start-up.
bash --rcfile .bwwbashrc
From the bash man page:
--rcfile file
Execute commands from file instead of the standard personal initialization
file ~/.bashrc if the shell is interactive (see INVOCATION below).
If you want to replace your current shell (with commands and settings from .bashrc), you can run
exec bash --rcfile .bwwbashrc

Related

How to know which file sourced a particular file

Ubuntu 16.04; zsh; oh my zsh; KDE
I have many dotfiles like .bashrc, .commonrc, .zshrc sourcing each other. Say I want to stop sourcing a particular file .bash_docker. Is there a way to know which file sourced it?
I figured it out through manual examination, but it happens quite often... It seems like source has no man page or help option.
Try printing this in your target script
echo "This script sourced from : ${BASH_SOURCE[1]}"
Here are the bash variables of interest for reference
https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html

Why must I run . ~/.bashrc each time I want to access my shortcuts there?

To speed up some of my Linux commands, I followed the recommendations of this Lifehacker article by writing aliases to quickly cd into folders I like. Fran's answer to "source" the .bashrc file by executing this line enabled me to use my shortcuts:
. ~/.bashrc
Like the OP in this post, it is unclear to me how to always access my shortcuts without having to rerun that command.
This is an issue lots of people run into when new to Bash. It comes from not understanding which files are read when.
Your .profile or .bash_profile is read when you log on. This is a login shell.
Your .bashrc is run whenever you start another interactive shell.
Typically you will want to include a source ~/.bashrc as the last thing that happens in your profile to ensure that your login shell has these same aliases.
Per the bash man page:
When an interactive shell that is not a login shell is started, bash
reads and executes commands from ~/.bashrc, if that file exists.
Therefore, every time you open a new interactive bash shell (such as when you open a new terminal), ~/.bashrc will automatically be read.

linux: passing arguments to the .bashrc file

I want to be able to run bash in different predefined configurations. for example: When i'm at work i'll do something like:
bash work
And it will load the appropriate environment variables.
The way i see it, the best way of doing it is passing the configuration name to the .bashrc command and than just configure it according to the name.
To do that, i need to pass the name to the .bashrc file.. How do i pass arguments to the .bashrc file from the bash command?
Of course alternatives for doing what i want will be appreciated!
Thank you!
From the man page:
--rcfile file
Execute commands from file instead of the standard personal initialization file ~/.bashrc if the shell is interactive (see INVOCATION below).
I don't think you can pass arguments to your individual bashrc directly, but you can call a common bashrc from your customized rc files and then either use arguments or global variables.
If you just want to set some environment variables, you can of course just manually call your customised rc file. To make this a little nicer from your command line, you can define a respective alias:
alias load_work='~/.workrc'
or with a new bash
alias load_work='bash --rcfile ~/.workrc'

How to add in bash for auto completion of arcanist commands

I am new to linux.
I am trying to set up arcanist.
I am done with git clone and adding the path in environment variable, however I am confused on how to set up the tab completion for arcanist commands.
In the arcanist user guide it says that you need to add source /path/to/arcanist/resources/shell/bash-completion to your .bashrc, .profile files.
What are these files and how can I edit them to work with arcanist with the tab completion.
The .bashrc, found in your home directory, is the configuration file for that user for bash.
There is a global bashrc usually located in /etc/bashrc.
The difference to .profile is that the .bashrc is executed every time you start a terminal (bash) while .profile only once when you use a login shell.
The command source loads everything that is inside the file you use with that command and treats it as if you wrote those commands in the .bashrc yourself. I guess in /path/to/arcanist/resources/shell/bash-completion are aliases/functions/etc. which enable tab-completion with arcanist.
Edit: for bash, the profile file is usually called .bash_profile.
After lot of googling and asking people, I finally did it.
First of all I had to export the path where my arcanist code from the github has been cloned in the ~/.bashsrc file(in bold below)
export PATH="$PATH:$HOME/.rvm/bin:$HOME/arcanist/bin/"
After this command, I copied the function which was present in the /arcanist/resources/shell/bash-completion into the bashrc file
And then I closed and open the terminal and bingo I was able to get arc and it's command as auto completion on striking tab.
Thanks ap0 for the comments.

How to set PATH in Knoppix?

I'm using knoppix 7.0.3 and trying to set the PATH environment variable. According to the official Ubuntu documentation, /etc/environment should be the preferred place for this. So I added these lines in the file:
JAVA_HOME="/usr/lib/jvm/java-6-sun"
GRAILS_HOME="/home/knoppix/grails"
PATH="${PATH}:${JAVA_HOME}/bin:${GRAILS_HOME}/bin"
But after rebooting the system, the file just reverted to the original one (I was using persistent storage).
Then after some Googling, I tried to edit ~/.profile like this:
export JAVA_HOME="/usr/lib/jvm/java-6-sun"
export GRAILS_HOME="/home/knoppix/grails"
export PATH=$PATH:$JAVA_HOME/bin:$GRAILS_HOME/bin
This time, the first two variables got set (echoed in console), but the PATH didn't. It was still the default one when I echoed. What's wrong?
Modify /etc/profile on the following line:
PATH=".:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
The problem is that your PATH is being overwritten during initialization of bash, after reading .profile.
From the manpage of bash:
When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. The --noprofile option may be used when the shell is started to inhibit this behavior.
...
When an interactive shell that is not a login shell is started, bash reads and executes commands from ~/.bashrc, if that file exists. This may be inhibited by using the --norc option. The --rcfile file option will force bash to read and execute commands from file instead of ~/.bashrc.
From your experience, it is apparent that if .bashrc doesn't exist, bash is trying to set PATH to a default value (I would appreciate if someone confirms this).
As we discussed in the comments on your question, adding the export commands to .bashrc (and thus creating the file) solves the problem. Alternatively, you can add
source ~/.profile
to the end of your .bashrc file for the same effect.

Resources