Linux: bashrc. How to load bashrc content from another file?

0

I occasionally have to re-install operating systems on the various linux machines which I manage. Every time I do this, I have to copy the .bashrc file to a USB drive before wiping the old system, and then put it back after I've installed a new system. (And perhaps edit it if something is no longer compatiable.)

This is annoying, and I usually stick to one version of a Linux OS and install it on most of my machines, so I've been trying to store my .bashrc content in a new file inside my Dropbox folder.

For example, I have put HISTTIMEFORMAT="%F %T " in a file named mybash inside my Dropbox folder.

What do I need to put inside my .bashrc file to "load all the stuff from the mybash file"?

I tried this, but it didn't seem to work?

# Load bash custom files
if [ -f /home/user/Dropbox/mybash ]
then
    . /home/user/Dropbox/mybash
fi

user3728501

Posted 2018-01-03T12:00:54.030

Reputation: 1 090

Just a suggestion. Why not create a git repository and host on github. And when you want it just do a git clone. – C0deDaedalus – 2018-01-03T14:29:29.920

@C0deDaedalus Good idea could also do this - Dropbox was just a quick easy way – user3728501 – 2018-01-03T15:29:32.670

Answers

0

I fixed the problem using some info found here.

Menu -> Edit -> Preferences -> General -> Tick the box: run as login shell

Thanks to AnythingIsFine for pointing me in the right direction.

This is an XFCE Terminal specific solution.

user3728501

Posted 2018-01-03T12:00:54.030

Reputation: 1 090

-1

Are you sure that the user which is sourcing the .bashrc file has permsission to read from:

. /home/user/Dropbox/mybash

Users can't read from one another's home dirs, unless specifically configured to do so.

The real reason might be because you are missing your

~/.bash_profile

file which sources your

~/.bashrc

where you finally instructed to source your mybash file.

You should add your code to the:

~/.bash_profile

instead.

AnythingIsFine

Posted 2018-01-03T12:00:54.030

Reputation: 220

I am the same user so my guess would be yes? – user3728501 – 2018-01-03T14:16:08.290

I edited my comment to show the cause I suspect. – AnythingIsFine – 2018-01-03T14:43:33.567

I have no .bash_profile file on my system. What am I supposed to put in it? – user3728501 – 2018-01-03T15:30:48.133

List all the files from /home (including hidden files) and see which one is sourcing ".bashrc". It may be simply named ".profile" as well. – AnythingIsFine – 2018-01-03T16:33:50.637

It seems to be .profile. What should I put in this file to load contents from another? – user3728501 – 2018-01-03T16:44:29.923

Same as what you put in your original question, the if condition and the source of "mybash", thr login again and check your history log for timestamp – AnythingIsFine – 2018-01-03T16:54:31.933

Why does "nesting" not work? eg; One file loads another which loads another? – user3728501 – 2018-01-03T16:55:08.170

Still doesn't seem to be working either way... – user3728501 – 2018-01-03T16:57:13.193

Are you using "su - user" to login ? – AnythingIsFine – 2018-01-03T17:08:06.437

No I login using xfce4? Sorry not sure if I understand the question? – user3728501 – 2018-01-03T22:32:45.207

I'm not familiar with the XFCE terminal you use to login, but please login as a different user and then issue the "su - <user>" to see if your file is sourced. – AnythingIsFine – 2018-01-04T07:59:09.113

Did that no difference – user3728501 – 2018-01-04T12:07:51.023

Are you sure you are using "bash" as a login shell ? please run this command "echo $SHELL" – AnythingIsFine – 2018-01-04T12:18:00.280

It's definitely bash /bin/bash – user3728501 – 2018-01-04T14:08:46.310

Then, it might be because of your login terminal, XFCE4. Take a look at the below 2 links to see if it helps...Ubuntu or Unix

– AnythingIsFine – 2018-01-04T14:29:58.253