Bashrc or bash_profile?

1

as camelot has said, shell initialization files do not exist by default. you will want to create a .bash_profile

nano $home/.bash_profile

feel free to use whatever text editor you prefer, including a nice gui text editor such as textwrangler, or one of the workhorse unix text editors such as vi, vim, or emacs.

you would put the export commands into the .bash_profile

export java_home="/sw/soylatte16-i386-1.0.2"

export path="/sw/soylatte16-i386-1.0.2/bin:$path"

now restart your terminal session, and you should have an updated path, as well as a java_home environment variable.

with respect to /sw, that is where the fink open source package manager stores things . if you have not installed fink, and if you did not use fink to install your java package, then the instructions you are following do not apply to your java installation.

if you installed java directly, the it might be installed under /usr/local directory...

0 0
2

I'm setting up my systems at work which includes setting up my session terminal windows on various Linux servers. At times like these, the question runs through my mind as to which configuration file to use for my login scripts, .bash_profile or .bashrc. For my Windows readers, we're talking Linux today.

We're also talking the BASH shell here, not the CSH or KSH, although they have similar files on start up. A shell is a terminal window with a command line prompt that you see when you login to a Linux server. It gives you a command line interface to the Linux operating system, as opposed to a desktop like you have in Windows.

So when do you use one or the other?

When you first login to a Linux shell, you want a way to run shell commands, set your PATH, and set environmental options for that paricular server session. The .bash_profile file is run when your first open your terminal window, or any window, that requires you to login.

Actually, when...

0 0
3

Let's learn when .bash_profile and .bashrc are called ...

For account postgres, I configure the two files as such ...

.bash_profile:

echo 'running .bash_profile'

.bashrc:

echo 'running .bashrc'

Result:

$ ssh postgres@localhost running .bash_profile

Hmmm, .bashrc was not run.

If I immediately subshell though ...

$ bash running .bashrc

.bashrc was not run for the initial process creation, but for sub-shells, it is run.

Sooooo:

.bash_profile runs at the start of a login session.bashrc runs during the creation of a sub-shell

Naturally, you want .bashrc to run for that initial process, after logging in, so it needs to be loaded manually.

.bash_profile:

echo 'running .bash_profile' [[ -f ~/.bashrc ]] && . ~/.bashrc

Resulting in the desired behavior:

$ ssh postgres@localhost running .bash_profile running .bashrc

This is on Gentoo. I seems possible that other Linux distributions may have alternative...

0 0
4
...
0 0
5

I'm trying to install rvm, and it wants me to edit my .bashrc or .bash_profile files to include rvm... But I can't FIND these files anywhere. A quick google search shows that they might not exist until I make them (weird), but I can't see any reference to WHERE I should make them.

EDIT: Okay, it from one of the responses, it looks like I need to put them in my /home directory...and I can use ls -la to see if they are really there or not (they are not), but when I make the files, and put:

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"

in them, as instructed by rvm, even when I make a new shell, I still can't type "rvm" and get anywhere.

Does that mean the files are in the wrong place, or that I made them wrong, or that the thing I put in them is wrong....I don't even know where to begin...

I made the files (as root), by typing "vi .bashrc" and vi ".bash_profile"... but when I look at them, the files seem to be named just "bashrc" and...

0 0
6

One of the things you always have trouble remembering when working with linux is what is the correct ".profile" to edit when you want to automatically set environmental variables.

According to the bash man page, .bash_profile is executed for login shells, while .bashrc is executed for interactive non-login shells.

when you login when using a console, either physically at the machine or using ssh, .bash_profile is executed.

However, if you launch a terminal within a windowing system such as GNOME,KDE, launch the Emacs *shell* mode, or execute /bin/bash from within another terminal then .bashrc is executed.

Most people edit the files so one calls the other anyway.

To do this you need to open .bash_profile and uncomment the following lines (under the comment # include .bashrc if it exists):

if [ -f ~/.bashrc ];
then
source ~/.bashrc
fi

Now when we login to our machine from a console,.bashrc will get...

0 0
7

Questions:

I am trying to use plink as an ssh alternative on windows, but I am finding that when plink connects to a remote linux machine, it does not source .bash_profile or .bashrc.
Is there a different dot file I should create? Or is there another option?

For example, my bashrc file adds a directory to my path. This directory contains extra programs that I want to use, one being python.

This will not work:

plink host python

Where as this will:

plink host "source .bashrc;python"

When I use plink without a command parameter, it sources .bash_profile and everything works fine, but it appear that by merely sending a command plink will not source either file.

Is there a workaround?

Answers:

If you simply connect to a remote host via ssh or plink, it will start the login account’s default shell. If that shell is bash, bash will automatically source .bash_profile.

If you connect to a remote host via ssh or plink asking...

0 0
8

Hello,

First, I apologize if my terminology is incorrect; please correct me if a term isn't used properly, I'd love to make my language more precise.

Googling tells me that .bash_profile is sourced for log-in shells and .bashrc for interactive shells. What do these terms mean in the context of a computer cluster like orchestra? Is the shell I interact with directly (the one I had to ssh into) a login shell that sources only .bash_profile? If I submit a job through bsub and that accesses a node, does .bashrc get sourced locally in that node? If I submit many jobs, does .bashrc get sourced for every single job? Or does bsub not actually interact in any way with either of these files?

I ask because of git: I currently do all my coding locally for convenience. Whenever I make a change I want in the cluster, I push to github and then fetch and reset to the cluster-specific branch in orchestra (in my home directory).

I want orchestra to do this automatically...

0 0
9

A lot of this is borrowed from other sites, including the wiki
This by no means all-inclusive, please add on anything interesting along this topic

About ~/.bash_profile and ~/.bashrc

disclaimer: I don't use ~/.bash_profile or ~/.profile
there is plenty of documentation on the web on how to use these properly if you're interested

in fact, my ~/.bash_profile looks like this:

#!/bin/sh ### THIS IS A DUMMY FILE ### DON'T NEED TWO FILES TO DO ONE JOB ### LET'S CALL ~/.bashrc INSTEAD source ~/.bashrc

Now, if you choose to go this method, there's a little trick you can do to eliminate ~/.bash_profile altogether :twisted:

as root create file /etc/profile.d/bashrc.sh with contents:

#!/bin/sh source ~/.bashrc

AND

chmod +x /etc/profile.d/bashrc.sh

Since /etc/profile executes everything in /etc/profile.d/ that is chmod executable, the little script we just created will cause ~/.bashrc to be read on every login... I personally prefer this...

0 0
10

Eliot, thanks for the reply.

The passwd/group was an interesting thought. Unfortunately:

@oob2$ mkpasswd -l > passwd.new
@oob2$ diff passwd passwd.new
@oob2$ mkgroup -l > group.new
@oob2$ diff group group.new
@oob2$

It's not just mintty. When I run xterm, it doesn't source any of my
init files, either.

This is not a new issue. I only started to care about it recently
because I want to use ssh-agent/ssh-add in my .bashrc/.bash_profile.

As for PATH, it's set so that it can find the programs, so I'm pretty
sure that's neither here nor there.

More ideas for debugging?

Here's my mount output, in case that might be relevant:

bash-4.1$ mount
C:/cygwin/home on /home type ntfs (binary)
C:/cygwin/bin on /usr/bin type ntfs (binary,noacl)
C:/cygwin/lib on /usr/lib type ntfs (binary,noacl)
C:/cygwin on / type ntfs (binary,noacl)
C: on /c type ntfs...

0 0
11
bashrc bash_profile bash_aliases - Bash - SS64.com

~/.bashrc

From the bash man page:

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 can 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 can be inhibited by using the --norc option. The --rcfile file option will force bash to read and execute commands from file instead of ~/.bashrc

Every new terminal window/tab that you open will load .bashrc

On a brand new user account, none of these files will exist,...

0 0
12

The main difference with shell config files is that some are only read by "login" shells (eg. when you login from another host, or login at the text console of a local unix machine). these are the ones called, say, .login or .profile or .zlogin (depending on which shell you're using).

Then you have config files that are read by "interactive" shells (as in, ones connected to a terminal (or pseudo-terminal in the case of, say, a terminal emulator running under a windowing system). these are the ones with names like .bashrc, .tcshrc, .zshrc, etc.

bash complicates this in that .bashrc is only read by a shell that's both interactive and non-login, so you'll find most people end up telling their .bash_profile to also read .bashrc with something like

[[ -r ~/.bashrc ]] && . ~/.bashrc

Other shells behave differently - eg with zsh, .zshrc is always read for an interactive shell, whether it's a login one or not.

The manual page for bash explains the...

0 0
13

When working with Linux, Unix, and Mac OS X, I always forget which bash config file to edit when I want to set my PATH and other environmental variables for my shell. Should you edit .bash_profile or .bashrc in your home directory?

You can put configurations in either file, and you can create either if it doesn’t exist. But why two different files? What is the difference?

According to the bash man page, .bash_profile is executed for login shells, while .bashrc is executed for interactive non-login shells.

What is a login or non-login shell?

When you login (type username and password) via console, either sitting at the machine, or remotely via ssh: .bash_profile is executed to configure your shell before the initial command prompt.

But, if you’ve already logged into your machine and open a new terminal window (xterm) inside Gnome or KDE, then .bashrc is executed before the window command prompt. .bashrc is also run when you start a new bash...

0 0
14

.bash_profile is executed for login shells, while .bashrc is executed for interactive non-login shells.

When you login (type username and password) via console, either sitting at the machine, or remotely via ssh: .bash_profile is executed to configure your shell before the initial command prompt.

But, if you’ve already logged into your machine and open a new terminal window (xterm) then .bashrc is executed before the window command prompt. .bashrc is also run when you start a new bash instance by typing /bin/bash in a terminal.

On OS X, Terminal by default runs a login shell every time, so this is a little different to most other systems, but you can configure that in the...

0 0
15

Put everything in .bashrc and then source .bashrc from .profile

From the bash man page (on OS X 10.9):

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

The above text is why everything is put in .bashrc. However, there's a bit different behavior when you're dealing with a login shell. Again, quoting from the man page:

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...

0 0
16

.bashrc is a shell script that Bash runs whenever it is started interactively. It initializes an interactive shell session. You can put any command in that file that you could type at the command prompt.

You put commands here to set up the shell for use in your particular environment, or to customize things to your preferences. A common thing to put in .bashrc are aliases that you want to always be available.

.bashrc runs on every interactive shell launch. If you say:

$ bash ; bash ; bash

and then hit Ctrl-D three times, .bashrc will run three times. But if you say this instead:

$ bash -c exit ; bash -c exit ; bash -c exit

then .bashrc won't run at all, since -c makes the Bash call non-interactive. The same is true when you run a shell script from a file.

Contrast .bash_profile and .profile which are only run at the start of a new login shell. (bash -l) You choose whether a command goes in .bashrc vs .bash_profile depending on on whether you want...

0 0
17
# =============================================================== # # # PERSONAL $HOME/.bashrc FILE for bash-3.0 (or later) # By Emmanuel Rouat [no-email] # # Last modified: Tue Nov 20 22:04:47 CET 2012 # This file is normally read by interactive shells only. #+ Here is the place to define your aliases, functions and #+ other interactive features like your prompt. # # The majority of the code here assumes you are on a GNU #+ system (most likely a Linux box) and is often based on code #+ found on Usenet or Internet. # # See for instance: # http://tldp.org/LDP/abs/html/index.html # http://www.caliban.org/bash # http://www.shelldorado.com/scripts/categories.html # http://www.dotfiles.org # # The choice of colors was done for a shell with a dark background #+ (white on black), and this is usually also suited for pure text-mode #+ consoles (no X server available). If you use a white background, #+ you'll have to do some other choices for readability. # # This bashrc file is a bit...
0 0
18

.bash_profile is a script that is executed each time you start a new shell. On Linux, it's called under different circumstances than .bashrc, but on OS X, they work exactly the same way. Any command you add to the file will be run whenever you open a new terminal window (thus starting a new interactive shell).

$PATH is a variable that tells the shell where to look for executable files - so when you type a command, the system will search each directory specified in that variable until it finds an executable program with that command's name.

The command export PATH=/usr/local/bin:$PATH prepends the directory /usr/local/bin to the current PATH, so it becomes the first directory searched by the shell.

.bash_profile just a normal plain text file - you can edit it with any text editor, including vi or nano, or even a graphical editor like TextEdit. It's up to you - just remember to save it as a plain-text...

0 0