LinuxQuestions.org
Visit the LQ Articles and Editorials section
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 02-06-2009, 03:46 AM   #1
linuxFool.lrn
LQ Newbie
 
Registered: Feb 2009
Posts: 4

Rep: Reputation: 0
is .bash_profile the same as .bashrc in ubuntu


I am trying to add export PATH=$PATH:directory to my .bash_profile. I am not able to find .bash_profile. Is it the .bashrc? If not do I need to create the .bash_profile and if so where?
 
Old 02-06-2009, 03:51 AM   #2
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 61
Create the .bash_profile file. As for the difference, read bash's man page (at the start).

Yves.
 
Old 02-06-2009, 04:13 AM   #3
linuxFool.lrn
LQ Newbie
 
Registered: Feb 2009
Posts: 4

Original Poster
Rep: Reputation: 0
Obtuse?

Sorry if I am being obtuse! But do I create this at ~$ and what is bash's man page?
 
Old 02-06-2009, 04:27 AM   #4
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,040

Rep: Reputation: 373Reputation: 373Reputation: 373Reputation: 373
To read a given man page use "man <whatever>" on a terminal, for example:

Code:
man bash
The section you are looking for is titled "INVOCATION", all the bash initialization files are defined on that place. And no, ~/.bashrc and ~/.bash_profile are not the same, though both are bash init files, but used for different purposes. They both will reside in your home if they exist. If not, you can create them by editing them with any text editor, it doesn't matter if it's a graphical editor or a command line based one.
 
Old 02-06-2009, 01:52 PM   #5
linuxFool.lrn
LQ Newbie
 
Registered: Feb 2009
Posts: 4

Original Poster
Rep: Reputation: 0
Thanks!
 
Old 02-06-2009, 03:38 PM   #6
linuxFool.lrn
LQ Newbie
 
Registered: Feb 2009
Posts: 4

Original Poster
Rep: Reputation: 0
Stumped!

I am trying to follow a tutorial on writing scripts.

I was instructed to edit .bash_profile and add the following

alias l='ls -l'

I created the .bash_profile as above, changed permission to 755 per chmod. Then I loged out/in. My understanding is that this should make "l" a command in my terminal.

I have also tried adding #! /bin/bash and #! /bash. Still get :command not found!

What am I missing?
 
Old 02-06-2009, 07:53 PM   #7
jay73
Guru
 
Registered: Nov 2006
Location: Belgium
Distribution: Ubuntu 11.04, Debian testing
Posts: 5,019

Rep: Reputation: 130Reputation: 130
Some distros do not use "bash_profile" but "profile". The thing works exactly the same, only its name is different.
 
Old 02-06-2009, 08:28 PM   #8
ahc_fan
LQ Newbie
 
Registered: Jan 2009
Posts: 9

Rep: Reputation: 0
Bash searches for .bash_profile, .bash_login, and .profile, in that order and uses the first one it finds. I believe aliases go in .bashrc because .bash_profile is used only once at login and subsequent shells (i.e., terminal emulators in the desktop environment) only inherit the shell variables.
 
Old 02-07-2009, 12:04 PM   #9
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,040

Rep: Reputation: 373Reputation: 373Reputation: 373Reputation: 373
Quote:
Originally Posted by jay73 View Post
Some distros do not use "bash_profile" but "profile". The thing works exactly the same, only its name is different.
Nope.

It's all in the man page, as I said previously. It's a bash thing, and has nothing to do with your distro at all, unless your distro patches bash that is, which is very unlikely because bash is the most widely used shell in Linux, and should always remain compatible across distros as far as possible. Read the "INVOCATION" section.

Bash look in many files, depending on how it is invoked.

If it stats as an interactive login shell it will look first into /etc/profile, then it will look into one and only one between these three files: ~/.bash_profile, ~/.bash_login and ~/.profile. Only the first file that is found will be sourced and the rest of them will be ignored, even if the first tile is just an empty file. Something that's good to keep in mind.

Non-login interactive shells, however, don't read any of these files. So, if you are opening terminals on X (xterm, urxvt, konsole, gnome-terminal or whatever else) the file you should use is ~/.bashrc.

Again, all in the man page. Please, use it.
 
Old 02-07-2009, 12:21 PM   #10
vasmakk
Member
 
Registered: Jan 2009
Distribution: Debian Lenny, Ubuntu 9.04
Posts: 87

Rep: Reputation: 16
Quote:
Originally Posted by linuxFool.lrn View Post
I am trying to follow a tutorial on writing scripts.

I was instructed to edit .bash_profile and add the following

alias l='ls -l'

I created the .bash_profile as above, changed permission to 755 per chmod. Then I loged out/in. My understanding is that this should make "l" a command in my terminal.

I have also tried adding #! /bin/bash and #! /bash. Still get :command not found!

What am I missing?
First of all, you have a typo! not alias l ... but alias ls ... (unless you want to use l in place of ls).
Put the command alias ls='ls -l' in your .bashrc file.
Don't need for .bashrc to be executable, for this command to work.

In my system i have a .bashrc file with only one line:
alias ls='ls --color'

Regards!
Vas

Last edited by vasmakk; 02-07-2009 at 12:22 PM.
 
Old 02-07-2009, 01:13 PM   #11
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,040

Rep: Reputation: 373Reputation: 373Reputation: 373Reputation: 373
Quote:
Originally Posted by vasmakk View Post
First of all, you have a typo! not alias l ... but alias ls ... (unless you want to use l in place of ls).
I think that's the whole point, so he can still use ls as normal without having to unalias it first. You don't want -l always, for example if you are in a dir with hundreds of images and you only want to search for one or look at the names.

Quote:
Put the command alias ls='ls -l' in your .bashrc file.
Don't need for .bashrc to be executable, for this command to work.
That's true and I forgot to comment on that, the only permissions you need for it to be sourced is 400 (read for user, nothing else). But usually 600 ir right, so you can also modify it later. The rest of the users shouldn't have access to your bashrc. Note that bashrc (just like the rest of the bash rc files) is "sourced", and not "executed". It doesn't need +x permissions.
 
Old 02-07-2009, 08:18 PM   #12
okos
Member
 
Registered: May 2007
Location: California
Distribution: Slackware/Ubuntu
Posts: 609

Rep: Reputation: 37
All you ever wanted to know about bashrc and bash_profile
http://humanreadable.nfshost.com/sdeg/bash_startup.htm

His user name on is Woodsman on LQ
 
Old 02-08-2009, 04:38 AM   #13
brianL
LQ 5k Club
 
Registered: Jan 2006
Location: Oldham, Lancs, England
Distribution: Slackware & Slackware64 14.1
Posts: 7,030
Blog Entries: 52

Rep: Reputation: Disabled
I'm sure when I was running Ubuntu that there was a .bash_profile and a .bashrc in my home directory. In Nautilus, look for "Show hidden files" in one of the menus and click it.
 
Old 02-08-2009, 06:05 AM   #14
arizonagroovejet
Senior Member
 
Registered: Jun 2005
Location: England
Distribution: SLED, openSUSE
Posts: 1,022

Rep: Reputation: 173Reputation: 173
It is worth bearing in mind that some distros, I think Ubuntu is one, give new users a .bash_profile that contains:


Code:
# include .bashrc if it exists
if [ -f ~/.bashrc ]; then
    . ~/.bashrc
fi
So the default behaviour you see is that your .bashrc file is sourced in cases where the bash man pages indicate it isn't.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
bashrc vs. bash_profile mikeshn Linux - General 9 02-10-2008 01:46 PM
bashrc or bash_profile ? ARCIS_house Linux - Newbie 6 07-21-2005 02:09 PM
~/.bashrc, ~/.bash_profile Sinope Linux - Newbie 6 08-17-2004 02:40 AM
.bashrc or .bash_profile? statmobile Linux - Newbie 1 02-04-2004 09:08 PM
.bashrc vs .bash_profile xor3 Linux - Newbie 1 08-16-2003 12:52 PM


All times are GMT -5. The time now is 07:44 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration