LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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-05-2009, 02:11 PM   #1
mikeyd1985
LQ Newbie
 
Registered: Aug 2009
Posts: 10

Rep: Reputation: 0
can't find .bash_profile in Ubuntu 9.04


Hey guys,

I'm following along with linuxcommand.org on the command line and shell scripting. After writing the first script and getting it to run I'm instructed to add: export PATH=$PATH:home_directory to my .bash_profile so I will be able to run the script by typing: my_script rather than specifying the path: ./my_script. But I can't find it. All I have is bash_history, bash_logout, bashrc.

Any help would be appreciated
 
Old 10-05-2009, 02:13 PM   #2
uteck
Member
 
Registered: Oct 2003
Location: Elgin,IL,USA
Distribution: Sidux, LinHES, and Mythbuntu
Posts: 209

Rep: Reputation: 32
Go ahead and create the file with the line you want to add. Then either logout and back in, or type "source .bash_profile" to use it in that terminal window.
 
Old 10-05-2009, 03:54 PM   #3
mikeyd1985
LQ Newbie
 
Registered: Aug 2009
Posts: 10

Original Poster
Rep: Reputation: 0
Okay so I created the .bash_profile and added PATH=$PATH:/home/mikeyd. I then logged out and in again and it wouldn't work. So then I put in the command "$PATH" and recieved this:

bash: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games: No such file or directory

Then after I put in: "source .bash_profile"

it worked, but I have to source it every time I open a terminal. I typed in "$PATH" again and recieved this:

bash: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/mikeyd: No such file or directory

What am I doing wrong?
 
Old 10-05-2009, 06:27 PM   #4
Ahmed
Member
 
Registered: May 2005
Location: München, Germany
Distribution: Slackware, Arch
Posts: 386

Rep: Reputation: 41
Just a side note: Only writing $PATH is telling the terminal to execute your path as if it were a command, which doesn't do anything. 'echo $PATH' is the way to have it print out the path.

I don't know about Ubuntu, but there should be a file called /etc/profile, which is a system-wide bash profile. At least in Slackware there's a line at the end specifically for the $PATH of non-root users. Maybe you'd want to use that instead. It's guaranteed to work.

-A
 
Old 10-05-2009, 10:00 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,260

Rep: Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328
Show the content of your .bash_profile .
 
Old 10-06-2009, 10:41 AM   #6
freelinuxtutorials
Member
 
Registered: Oct 2009
Posts: 70

Rep: Reputation: 21
It seems the script works on RPM-based distro such as Fedora,Redhat since the default shell of it is bash.
Can you try to check your current shell via
echo $SHELL

BTW, in debian based, shell is zsh and equivalent is .profile
 
Old 10-06-2009, 07:43 PM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,260

Rep: Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328
Another thing I've noticed is when you 'logout', you have to logout completely, not just exit the current xterm.
GUI environments seem to cache your login settings when you first login & apply those to all child xterms.
 
Old 10-06-2009, 11:29 PM   #8
bartonski
Member
 
Registered: Jul 2006
Location: Louisville, KY
Distribution: Fedora 12, Slackware, Debian, Ubuntu Karmic, FreeBSD 7.1
Posts: 443
Blog Entries: 1

Rep: Reputation: 47
From the bash man pages:

Quote:
INVOCATION
A login shell is one whose first character of argument zero is a -, or one started with the --login option.

An interactive shell is one started without non-option arguments and without the -c option whose standard input and error are both connected to
terminals (as determined by isatty(3)), or one started with the -i option. PS1 is set and $- includes i if bash is interactive, allowing a
shell script or a startup file to test this state.

The following paragraphs describe how bash executes its startup files. If any of the files exist but cannot be read, bash reports an error.
Tildes are expanded in file names as described below under Tilde Expansion in the EXPANSION section.

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 /etc/bash.bashrc and ~/.bashrc, if these
files exist. 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 /etc/bash.bashrc and ~/.bashrc.
Ok, so what does that mean for you? A terminal launched inside of X (Gnome, KDE, etc) is not a login shell, so you will have to put your path information into ~/.bashrc or /etc/bash.bashrc, since these are the only rc (run-control) files run when you launch a terminal window.

The same cannot be said if you log in from the console (i.e. if you get out of X using <ctrl><alt><F1>)... this will be a login shell and will use ~/.bash_profile, ~/.bash_login and ~/.profile.

Last edited by bartonski; 10-06-2009 at 11:32 PM.
 
Old 10-08-2009, 07:04 PM   #9
rsciw
Member
 
Registered: Jan 2009
Location: Essex (UK)
Distribution: Home: Debian/Ubuntu, Work: Ubuntu
Posts: 206

Rep: Reputation: 44
Quote:
Originally Posted by freelinuxtutorials View Post
It seems the script works on RPM-based distro such as Fedora,Redhat since the default shell of it is bash.
Can you try to check your current shell via
echo $SHELL

BTW, in debian based, shell is zsh and equivalent is .profile
all debian and debian based distros I used come with bash as default shell.
zsh needs to be installed via apt-get
 
Old 10-08-2009, 07:09 PM   #10
jay73
LQ Guru
 
Registered: Nov 2006
Location: Belgium
Distribution: Ubuntu 11.04, Debian testing
Posts: 5,019

Rep: Reputation: 130Reputation: 130
Ubuntu uses .profile instead.
 
Old 10-08-2009, 07:43 PM   #11
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671
Add "export PATH" at the end of your .bash_profile or .profile script. This moves a variable to your environment.
The .profile, .bash_login or .bash_profile script will be executed for a login shell. Bash looks for them in that order and executes the first one it finds.

For most distro's if you have a $HOME/bin/ directory, the /etc/profile script or $HOME/.profile script will add it to your PATH variable. Read your /etc/profile script and see if it does that. On my system, a profile script will also check for a $HOME/.bashrc script and source it if it exists. A bin/ directory in your home directory would be a better place for your personal scripts.
 
  


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
Can't find my .bash_profile Allanitto Newbee Slackware - Installation 10 05-28-2009 07:57 PM
Cnt Find .bash_profile minky81 Linux - General 4 09-13-2007 06:05 AM
Cnt Find .bash_profile minky81 Linux - Newbie 1 09-12-2007 11:42 AM
Installing MySQL, can't find .bash_profile to edit! blanderson Linux - Newbie 3 10-13-2003 02:52 PM


All times are GMT -5. The time now is 09:53 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration