Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Just upgraded to 11.10, and prompted me to wondering where is now the preferred way to put customised .bashrc bits?

I have some aliases, some env variables, and a python virtualenvwrapper script, for instance, which I want to run as part of my .bashrc. I have these synced in a script across machines stored in Dropbox.

I used to put them at the bottom of .bashrc, and then I put them in a file called .bash_profile which it sourced, but now I see that .bashrc no longer sources .bashrc_local (did it ever or did I customise this?), and I note that it sources .bash_aliases and .bash_completion.

So I've decided as it's non existent at the mo to put the stuff in .bash_aliases, as it seems cleanest to have my customisations in a separate file to the default.

I got scared off .profile as it already has stuff in it.

I realise what I'm doing works, but it seems a bit counter intuitive to be putting these things in a file called aliases when it's not all aliases.

Is this the correct place for this?

share|improve this question
    
possible duplicate of Where to declare environment variables? –  belacqua Oct 14 '11 at 15:12
    
Personally, if it's just one account, I use only .bash_aliases for aliases and .bashrc for the other stuff. –  belacqua Oct 14 '11 at 15:15
add comment

2 Answers

Startup scripts are a bit of a maze, aren't they?

I believe that it basically works out that .profile is executed for login shells -- i.e., what you'd get if you login remotely -- and .bashrc is used for non-login shells, assuming you're using bash. .profile sources .bashrc, so in general you'd put stuff you always use in .bashrc, like additions to the default path and other environment settings. I believe the general convention in *nix systems and bash is to do most of the customization in .bashrc; I haven't seen .bash_aliases on Red Hat-family Linux distributions or the Unix systems I've used. I don't remember ever seeing a .bash_local.

The way .bash_aliases is sourced seems like a good model, so it might be tidier to do your customizations in another file, adding this to the end of .bashrc:

# Local customized path and environment settings, etc.
if [ -f ~/.bash_local ]; then
    . ~/.bash_local
fi

It can be helpful to look at /etc/skel, where the default user scripts are that are copied to new users' home directories, and at /etc/profile and /etc/bash.bashrc, which are system-wide defaults.

I think the underlying assumption to all of this is that the user can do as the user pleases with personal copies of .profile, .bashrc, etc., so no presumptions are made about what is or is not in them.

share|improve this answer
    
I don't know what's gone wrong with the formatting, but I think the meaning of the code snippet should be obvious. –  bgvaughan Oct 14 '11 at 13:17
add comment

I suspect .bashrc_local is an invention of yours. Me too have something similar, with an expression like this in ~/.bashrc

if [[ -r ~/.bashrc_local ]]; then
    . ~/.bashrc_local
fi

but I put in this file only customization specific to the given machine, and let the customization common to all my machines in ~/.bashrc, synced in some way.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.