LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-30-2008, 11:54 PM   #1
Kiwi944
Member
 
Registered: Jan 2008
Location: Auckland
Distribution: Ubuntu
Posts: 31

Rep: Reputation: 15
.bash_profile not executed at login


Hello All

First off I am new to Linux and trying to learn about shell scripts.

I have created a file (having not been able to locate it) in the following location:

/home/alan/.bash_profile

I have entered the following entries and rebooted but they don't seem to have been implemented.

Code:
alias l='ls -l'
Could someone please advise what I am doing wrong here as I am stuck.

Ubuntu 8.04 Desktop running in VPC 2007

Thanks in advance.
 
Old 10-31-2008, 12:07 AM   #2
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 405Reputation: 405Reputation: 405Reputation: 405Reputation: 405
Quote:
Originally Posted by Kiwi944 View Post
Hello All

First off I am new to Linux and trying to learn about shell scripts.

I have created a file (having not been able to locate it) in the following location:

/home/alan/.bash_profile

I have entered the following entries and rebooted but they don't seem to have been implemented.

Code:
alias l='ls -l'
Could someone please advise what I am doing wrong here as I am stuck.

Ubuntu 8.04 Desktop running in VPC 2007

Thanks in advance.
Read the INVOCATION section of the man bash page, for further reference.

I will briefly say here that .bash_profile is only for login shells (i.e. you login in text mode into a shell, not X). For shells inside terminal emulators, the file you need is ~/.bashrc.

In either case, you don't need to reboot, you just need to reload your shell. A time saver that I use is this:

Code:
exec bash
Which closes the current bash and opens a new one. That saves me the *huge* work of having to close my terminal and open a new one
 
Old 10-31-2008, 01:06 PM   #3
Kiwi944
Member
 
Registered: Jan 2008
Location: Auckland
Distribution: Ubuntu
Posts: 31

Original Poster
Rep: Reputation: 15
Thanks for the information and link, I will read it through. Thanks also for the hint with the time saver.
 
Old 06-25-2009, 01:37 AM   #4
gururaj.jois
LQ Newbie
 
Registered: Jun 2008
Posts: 16

Rep: Reputation: 0
.bash_profile not executed at login

Quote:
Originally Posted by i92guboj View Post
Read the INVOCATION section of the man bash page, for further reference.

I will briefly say here that .bash_profile is only for login shells (i.e. you login in text mode into a shell, not X). For shells inside terminal emulators, the file you need is ~/.bashrc.

In either case, you don't need to reboot, you just need to reload your shell. A time saver that I use is this:

Code:
exec bash
Which closes the current bash and opens a new one. That saves me the *huge* work of having to close my terminal and open a new one
Does it executes ~/.bashrc every time we login??
 
Old 06-25-2009, 03:42 AM   #5
mike11
Member
 
Registered: Apr 2009
Posts: 222

Rep: Reputation: 17
Yes: every login and every new bash terminal window you open.

There are three files which are supposed to be used in login shells: .bash_profile, .profile and .bash_login . I've found that only .profile is read.
 
Old 06-25-2009, 05:41 AM   #6
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 405Reputation: 405Reputation: 405Reputation: 405Reputation: 405
Quote:
Originally Posted by mike11 View Post
Yes: every login and every new bash terminal window you open.
Nope, unless ~/.bashrc is symlinked to either ~/.bash_profile, ~/.bash_login or ~/.profile.

~/.bashrc is only sourced on interactive non-login shells. As the man page says.

Quote:
There are three files which are supposed to be used in login shells: .bash_profile, .profile and .bash_login . I've found that only .profile is read.
These are, as you say, for login shells. In this case ~/.bashrc is not sourced.

They are searched for in this order from the first to the last: ~/.bash_profile, ~/.bash_login, and ~/.profile. Only the first one found is used. So, if ~/.bash_profile exists and is readable no other file should be sourced, even if ~/.bash_profile is an empty file. So there must be something weird on your system or your files.

Confusion can happen for many things. For example, when people create symlinks from ~/.bashrc to ~/.bash_profile (or any other similar file). Or when people who like to use root all the time create a ~/.bash_profile file in the home of other users. In this case the created file might not be readable and hence it's ignored.
 
Old 06-25-2009, 07:22 AM   #7
onebuck
Moderator
 
Registered: Jan 2005
Location: Central Florida 20 minutes from Disney World
Distribution: Slackware®
Posts: 13,925
Blog Entries: 44

Rep: Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159
Hi,

You could setup a .bashrc & .bash_profile for your user;

Code:
sample .bashrc;
:~$ cat .bashrc

#.bashrc
#08-30-06 12:20 

# Add bin to path

export PATH="$PATH:/sbin:/usr/sbin:$HOME/bin"

#export PATH="$PATH:$HOME/bin"

# Dynamic resizing
shopt -s checkwinsize

# Custom prompt
#PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '

#08-29-06 11:40

if [ `id -un` = root ]; then
   PS1='\[\033[1;31m\]\h:\w\$\[\033[0m\] '
 else
   PS1='\[\033[1;32m\]\h:\w\$\[\033[0m\] '
fi

#
# Add color
eval `dircolors -b`

# User defined aliases
alias cls='clear'
alias clls='clear; ls'
alias ll='ls -l'
alias lsa='ls -A'
alias lsg='ls | grep'
alias lsp='ls -1 /var/log/packages/ > package-list'
alias na='nano'
alias web='links -g -download-dir ~/ www.google.com'

#08-29-06 11:50

#To clean up and cover your tracks once you log off
#Depending on your version of BASH, you might have to use
# the other form of this command
   trap "rm -f ~$LOGNAME/.bash_history" 0

#The older KSH-style form
#   trap 0 rm -f ~$LOGNAME/.bash_history
Code:
sample .bash_profile;

~$ cat .bash_profile
# .bash_profile
#08-30-06 12:21 

# Source .bashrc
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi
The '.bashrc' is very useful!

EDIT: I generally check the OP date but missed this one.

Last edited by onebuck; 06-25-2009 at 07:23 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
~/.bash_profile not being executed at login Radicalm16 Slackware 9 07-28-2009 09:39 PM
.bashrc and .bash_profile not executed enlight1 Fedora 5 06-27-2006 08:24 PM
Cannt login as root . made changes to .bash_profile hotbacteria Linux - Newbie 3 01-31-2006 10:03 PM
Cannt login as root . made changes to .bash_profile hotbacteria Linux - Newbie 3 01-31-2006 10:02 PM
.bash_profile overwritten on login to root Awesome Dude Linux - Newbie 1 08-23-2004 02:41 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:43 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration