LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   Bash preferences within X (https://www.linuxquestions.org/questions/slackware-14/bash-preferences-within-x-163826/)

Shade 03-29-2004 01:29 PM

Bash preferences within X
 
Hey all,

I'm not exactly a noob, and I've searched this, but am looking for something in particular.

To get my xterms, aterms, and the like to display the right prompt, ls colors, etc, I've added

source /etc/profile

to .bashrc

This works fine as long as I stay in X. However, logging in to normal text console will display the fortune twice, as it's being read first from /etc/profile, then read again from .bashrc ...

Is there a simple way to have .bashrc source /etc/profile if I'm on a non-login shell, but not if I'm logging in from console?

--Shade

PS -- It's just the idea of redundancy that I'm trying to get around. I realize I could simply put PS1, my aliases and ls -color and so forth, but I'm trying to find a way to read the system-wide /etc/profile file only once, in all cases.

ringwraith 03-29-2004 03:01 PM

man bash

Tinkster 03-29-2004 03:14 PM

man bash
/.bashrc

The thing is that bash gets invoked differently
depending on whether a shell is a login-shell
or not... by default in X the shell's aren't login-
shells, thus evaluate .bashrc but not /etc/profile.

The bash on a console, on the other hand, is
a login-shell and will evaluate /etc/profile
and ~/bash_profile, ~/.bash_login and ~/.profile
(in this order, and stop at the first one found).

It shouldn't be using your ~/.bashrc, though,
which makes having fortune twice a bit strange.


Cheers,
Tink

Shade 03-29-2004 03:16 PM

Right, I thought it was strange...

I'm grokking the bash man page, again...

--Shade

Tinkster 03-29-2004 03:27 PM

Do you happen to have one of the other
three I mentioned as well, and sourcing
that from .bashrc ?


Cheers,
Tink

Shade 03-29-2004 03:31 PM

I'm a retard.

I had 'source /etc/profile' in .bash_profile, not .bashrc
.bash_profile is read only by a login shell...

From the O'Reilly Learning the Bash Shell book:
Quote:

If you start up a new shell by typing bash on the command line, it will attempt to read commands from the file .bashrc. This scheme allows you the flexibility to separate startup commands needed at login time from those you might need when you run a subshell. If you need to have the same commands run regardless of whether it is a login shell or subshell, you can just use the source fommand from within .bash_profile to execute .bashrc.
I understand the scheme now. .bashrc is read for subshells, .bash_profile for login shells. Login shells begin by reading /etc/profile, and continue on to read .bash_profile... That's where my problem was. All I need is the .bashrc to source /etc/profile, and subshells will behave the same.

--Shade


Tinkster 03-29-2004 03:41 PM

Or invoke the xterm (rxvt, konsole, whatever ...) with
a flag that makes it a login-shell as well ;)


Cheers,
Tink

Shade 03-29-2004 03:43 PM

I would have done that to begin with, but my instinct was to figure out the workings of it, and why it wasn't doing what I thought it should.

I learned a bit, and that was my goal. Plus it works how I like now. For some reason, I just didn't want login shells for every xterm I'd be opening ;)

--Shade


All times are GMT -5. The time now is 06:31 AM.