Bash_profile versus bashrc


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Bash_profile versus bashrc
# 1  
Old 03-18-2014
Bash_profile versus bashrc

Hi All

Please can you tell , what is the difference between
Code:
bash_profile

and
Code:
bashrc

. How to create them?
# 2  
Old 03-18-2014
The .bash_profile will be run at login only. The .bashrc will be run each time you start a sub-shell.

You can create them in lots of ways, for instance by editing the file name (it will create when you save) or by doing something like:-
Code:
dd<<-EOF >.bash_profile
#This is my .bash_profile
#I can insert lines in a block like this
#I can set values like this
val=12345
print "Hello!"
EOF

This is far more complex than just editing the file though.



I hope that this helps,
Robin
This User Gave Thanks to rbatte1 For This Post:
# 3  
Old 03-18-2014
I think the manual page summarises it up well enough:
Code:
       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 a login shell exits, bash reads and executes commands from the file ~/.bash_logout, if it exists.

       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.

You can create them as you would any other file - in your favourite editor.
# 4  
Old 03-18-2014
Bash_profile versus bashrc

Ok, thanks, but in waht circunstances we have to create
Code:
bashrc

, because I can see in one app that we have locally, that a user login with a specific user that, this user needs to type
Code:
bashrc

, to access the application
# 5  
Old 03-18-2014
Looks like .bashrc contains some commands or information that .profile doesn't. Print out .bashrc to see what's in there that might be needed for that application.
One option would be to source .bashrc from .profile so all interactive processes will have the same environment.
This User Gave Thanks to RudiC For This Post:
# 6  
Old 03-18-2014
Quote:
Originally Posted by fretagi
because I can see in one app that we have locally, that a user login with a specific user that, this user needs to type
Code:
bashrc

, to access the application
Perhaps in this "bashrc" there are some settings the user needs to start the application.

Note, though, that ".bashrc" and "bashrc" is not the same! The first one is the one which gets executed (automatically) every time the bash shell starts. The second one is just an ordinary file with a similar-looking name.

Further, in standard UNIX the current directory is not part of the PATH, so when you enter "bashrc" without anything, chances are you do not execute the file named "bashrc" in the current directory but an identically named file located elsewhere. Enter

Code:
which bashrc

to find out, where exactly the executed file is.

I hope this helps.

bakunin
This User Gave Thanks to bakunin For This Post:
# 7  
Old 03-18-2014
if its bashrc rather than .bashrc, thats means the person who wrote the scripts wants a kind of human decision... in the access of that application...

To answer your question, I dont think there is a "have to" but more customize to suit your needs, I for instance am responsible of SAS software on a server, but I am not a true SAS user..., I dont want people with no reason access SAS also, so for sure I will not put SAS in the PATH of /etc/profile...
I have written a script that sets all environment needed for SAS and their diverses apps... and that is put and called in the .profile of concerned users, but since I do have to use or chack SAS I have the script that I call when I need to... but there is nothing stopping you naming that file setenv4thatapp rather than bashrc that is a bit confusing... since its specific to an application environment

Last edited by vbe; 03-18-2014 at 11:01 AM.. Reason: typos and language...
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

.bash_profile question

Hello everyone, I'm trying to set my .bash_profile to change my primary prompt from this: banbatchtest1v:MCPPRD:~>to this: banbatchtest1v:MCPPRD:/home/rcarvall> Here's what my .bash_profile looks like right now: # .bash_profile # Get the aliases and functions if ; then .... (2 Replies)
Discussion started by: galileo1
2 Replies

2. UNIX for Dummies Questions & Answers

.bash_profile versus .profile of user in Solaris 10

Hi All I am kind of confused, when to use .bash_profile or .profile I have just created a user on a test server, with: useradd -u 103 -d /fretagi -m -s /bin/bash fretagi but now in its home dir I have: -bash-3.2$ ls -al total 14 drwxr-xr-x 2 fretagi other 512 Dec 5 15:54 .... (5 Replies)
Discussion started by: fretagi
5 Replies

3. UNIX for Advanced & Expert Users

bash_profile or .profile

Hi, happy new year. on AIX 6.1 , for user oracle , there are two files : bash_profile and .profile I do not know which one is executed when login ? How to know , More over in both of them we have : in .profile : ORACLE_HOME=/appli/oracle/product/10.2.0/db_1... (5 Replies)
Discussion started by: big123456
5 Replies

4. Solaris

allias in .bash_profile not working

I am using solaris 10 x86. I have created a .bash_profile under root's home directory(/). The contents of the file are: Solaris10u8/# cat .bash_profile export PATH=$PATH:/usr/sfw/bin export PS1='\h\w\$ ' export PAGER="less -imsq" alias ll='ls -l' alias la='ls -a' The problem is that: ... (7 Replies)
Discussion started by: proactiveaditya
7 Replies

5. UNIX for Dummies Questions & Answers

bash_profile does not working

Hi all. when i connect as user megaguru i have a problem my .bash_profile does not working^:( if i do: . ./.bash_profile all enviroment variables are in place. How can i force linux to use .bash_profile before logon process? thanx in advance. (1 Reply)
Discussion started by: smallman
1 Replies

6. Shell Programming and Scripting

question in .bash_profile

We are more users using the oracle account, and people want to include theyr own files in .bash_profile. Like this: while ; do echo -n "LOGNAME is '$LOGNAME' (no sens), who are you? " >/dev/stderr read ln export LOGNAME=$ln done This works well when logging in to... (1 Reply)
Discussion started by: hannem
1 Replies

7. Shell Programming and Scripting

.bash_profile problem

Hi Guys, I modified my .bash_profile script , and tried to change the prompt. Following is the line of code in my .bash_profile script. export PS1=" \W " But I get the output as: \W This appears to be my prompt now. Any idea what should be done.. Thanks! (0 Replies)
Discussion started by: nua7
0 Replies

8. UNIX for Dummies Questions & Answers

Unrecognized Path in .bash_profile

Dear experts, I have installed Ruby in the following directory: $ pwd /home/ewijaya/.ruby $ ls bin lib share And I have also stated the PATH in my bash_profile like this: # .bash_profile # Get the aliases and functions if ; then . ~/.bashrc (1 Reply)
Discussion started by: monkfan
1 Replies

9. UNIX for Dummies Questions & Answers

numbers on permanently through .bash_profile

Hi Can anyone tell me if it is at all possible to edit ones .bash_profile, to make the setting on of line numbers (in vi/vim), permanent? I've been to a few IRC channels and people keep telling me it is more of a vi/vim thing and to use something called ".vimrc", however I heard that it is... (3 Replies)
Discussion started by: zorrokan
3 Replies

10. UNIX for Dummies Questions & Answers

CTRL+H versus ^? versus BACKSPACE

Hi Gurus! I recently got my shell account (HP UX v11) created by our sysadmin and am having problem deleting with the backspace key. After doing some reading, I believe I need to enter a custom "STTY..." statement in my profile. Can someone please help me with the correct "STTY" sequence... (3 Replies)
Discussion started by: alan
3 Replies
Login or Register to Ask a Question