LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 09-22-2004, 12:45 AM   #16
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,290

Rep: Reputation: 378Reputation: 378Reputation: 378Reputation: 378

A couple of points to (hopefully) clarify things:

. <file> tells bash to source a particular file. What this means is bash basically executes the contents of the other file (there are some complications regarding subshells and the like that sourcing, as opposed to just plain executing, handles, but let's not worry about them at present).

The objective here is to have one set of common set-up commands that get executed for both login and nonlogin shells. For this to happen, we need to put the commands into one file. In my setup, I put all my personal set-up commands in .bashrc. But this is a problem, since then they aren't invoked in login shells. So I add the . ~/.bashrc to my .bash_profile to make .bash_profile run .bashrc and that way, .bashrc gets sourced regardless of whether I'm running a login or nonlogin shell. You could also do it the other way around and have .bashrc source your .bash_profile (where your custom setup commands would be located). Either way will work.

So, to summarize:

-- put your custom setup commands in either .bashrc or .bash_profile
-- have the other file source the file you put your commands into using . <filename>

If this does not work, post the exact errors that you get. Hopefully this helps a little and explains a bit of what's going on.
 
Old 09-22-2004, 01:17 AM   #17
Warmduvet
Member
 
Registered: Jun 2004
Location: New Zealand
Posts: 60

Original Poster
Rep: Reputation: 15
Thanks for your reply I understood the what and why but have not been able to get the how to work.
Will try again maybe I missed something.

WD
 
Old 09-22-2004, 01:36 AM   #18
Warmduvet
Member
 
Registered: Jun 2004
Location: New Zealand
Posts: 60

Original Poster
Rep: Reputation: 15
well putting

if [ -f ~/.bash_profile ]; then
. ~ /.bash_profile
fi

in my ~/.bashrc file didn't work.

after altering my user .bashrc as above I logout and try to login again I enter the user name hit enter, enter the password get the " your last login and date..." then "you have mail"
then instead of going to the user prompt I get returned to the original login prompt.

My setup stuff is in ~/.bash_profile which is why I am trying to source it from ~/.bashrc

WD

Last edited by Warmduvet; 09-22-2004 at 01:38 AM.
 
Old 09-22-2004, 03:09 AM   #19
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,290

Rep: Reputation: 378Reputation: 378Reputation: 378Reputation: 378
Can you do 'ls -l ~/.bash_profile .bashrc' then ... if your .bash_profile is a symlink it will not be sourced (because of the if [ -f ~/.bash_profile ] test). This seems unlikely, but worth a check. You can also put an echo statement into each file to see if/when it executes, e.g. in your .bashrc put:

echo .bashrc is running...
 
Old 09-22-2004, 04:11 AM   #20
Warmduvet
Member
 
Registered: Jun 2004
Location: New Zealand
Posts: 60

Original Poster
Rep: Reputation: 15
ls -l ~/.bash_profile returns the expected listing

this is my .bashrc file with 2 echos
when attempting to login the first echo "bashrc1 is running" repeats like
an endless loop until it kicks out back to the login prompt???
second echo " bashrc2 is running" doesnt appear at all.

# .bashrc

# User specific aliases and functions

echo "bashrc1 is running"

alias mntusb='sh mntusb.sh'
alias quit='sh quit.sh'
alias reup='sh reup.sh'

# Source global definitions
if [ -r ~/.bash_profile ]; then
. ~/.bash_profile
fi
echo " bashrc2 is running"

WD

Last edited by Warmduvet; 09-22-2004 at 04:13 AM.
 
Old 09-22-2004, 02:05 PM   #21
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Quote:
ls -l ~/.bash_profile returns the expected listing
What do you expect, and can we see it?

What's the content of .bash_profile, then?
There must be SOMETHING odd ...


Cheers,
Tink
 
Old 09-22-2004, 03:33 PM   #22
Warmduvet
Member
 
Registered: Jun 2004
Location: New Zealand
Posts: 60

Original Poster
Rep: Reputation: 15
Its ok I figured it out .bashrc was sourcing .bash_profile and .bashprofile was sourcing .bashrc
so endless loop once I commented out the sourcing in .bash_profile everything works the way it should although.... the prompt changes from

[xxx@jekyll xxx]#
to
-bash-2.05b$ I can change this using the PS1 or 2 shell variables ?


WD

PS thanks for all the help Tink and btmiller

PPS you get up early Tink

Last edited by Warmduvet; 09-22-2004 at 03:35 PM.
 
Old 09-22-2004, 05:05 PM   #23
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Quote:
Originally posted by Warmduvet
Its ok I figured it out :o .bashrc was sourcing .bash_profile and .bashprofile was sourcing .bashrc
so endless loop once I commented out the sourcing in .bash_profile everything works the way it should although....
DOH :)

Quote:
the prompt changes from

[xxx@jekyll xxx]#
to
-bash-2.05b$ I can change this using the PS1 or 2 shell variables ?
Sure you can ... just check where they're being
re-set, too.

Quote:
PPS you get up early Tink :D
Indeed ... ~ 0520 ;)
But I'm home from work ~ 1620, too!


Cheers,
Tink
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Mozilla working differently! redhatrosh General 2 05-04-2005 12:29 AM
applet on linux server behaves differently naijaguy Programming 3 01-07-2005 02:09 PM
Configuring the way mandrake 9.2 looks/behaves.. tinaldor Mandriva 7 11-14-2003 04:49 AM
pppd behaves strange Castor Linux - Networking 3 09-24-2003 08:12 AM
XMMS runs differently with different users infamous41md Linux - Newbie 8 05-18-2003 06:05 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 01:43 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
Open Source Consulting | Domain Registration