Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Equivalent of /etc/profile
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
Sivar
Apprentice
Apprentice


Joined: 25 May 2002
Posts: 266
Location: USA

PostPosted: Sun Jul 21, 2002 12:21 am    Post subject: Equivalent of /etc/profile Reply with quote

Quick Q:
Gentoo has an /etc/profile for Bash, but it doesn't seem to, er, ever get executed. What is the preferred place to put aliases, export statements, changes to the prompt (PS1=) etc?
_________________
The greatest deeds are still undone, the greatest songs are still unsung...
Back to top
View user's profile Send private message
Jesse
Tux's lil' helper
Tux's lil' helper


Joined: 24 Apr 2002
Posts: 148

PostPosted: Sun Jul 21, 2002 1:07 am    Post subject: Reply with quote

whoa .... that _is_ the place to put _some_ stuff like that. It should definately get executed as long as your using a login shell. This means that when you log in from an actual console or use something like konsole with the --ls parameter, this file should get 'sourced'. My /etc/profile has both a custom prompt as well as exports and an alias ...

You may also edit your appropriate ~/.bash_profile if you dont want those exports and alias to be global.
Back to top
View user's profile Send private message
shadow
n00b
n00b


Joined: 30 Jun 2002
Posts: 16
Location: ph

PostPosted: Sun Jul 21, 2002 1:53 pm    Post subject: Re: Equivalent of /etc/profile Reply with quote

Sivar wrote:
Quick Q:
Gentoo has an /etc/profile for Bash, but it doesn't seem to, er, ever get executed.

i noticed that, too. what i did was edit my ~/.bashrc file and added a call to /etc/profile.
Back to top
View user's profile Send private message
nbensa
l33t
l33t


Joined: 10 Jul 2002
Posts: 799
Location: Buenos Aires, Argentina

PostPosted: Sun Jul 21, 2002 2:09 pm    Post subject: Re: Equivalent of /etc/profile Reply with quote

ShADoW wrote:
Sivar wrote:
Quick Q:
Gentoo has an /etc/profile for Bash, but it doesn't seem to, er, ever get executed.

i noticed that, too. what i did was edit my ~/.bashrc file and added a call to /etc/profile.


Same here, but shouldn't bash source /etc/profile without telling him to do it?
Back to top
View user's profile Send private message
Jesse
Tux's lil' helper
Tux's lil' helper


Joined: 24 Apr 2002
Posts: 148

PostPosted: Sun Jul 21, 2002 2:36 pm    Post subject: Reply with quote

Code:

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 an interactive shell that is not a login  shell  is  started,  bash reads  and  executes commands from ~/.bashrc, if that file exists.  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 ~/.bashrc.


That's from the bash man pages of course .... the only time .bashrc is sourced is when the shell is _not_ a login shell. Are we talking about logging in from an actual console or with some X terminal emulator? Have you tried 'su -' and seen if that worked? Have you tried connecting from a different computer to see if the login is triggered there?
Back to top
View user's profile Send private message
Sivar
Apprentice
Apprentice


Joined: 25 May 2002
Posts: 266
Location: USA

PostPosted: Sun Jul 21, 2002 3:18 pm    Post subject: Reply with quote

Jesse wrote:
Code:

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 an interactive shell that is not a login  shell  is  started,  bash reads  and  executes commands from ~/.bashrc, if that file exists.  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 ~/.bashrc.


That's from the bash man pages of course .... the only time .bashrc is sourced is when the shell is _not_ a login shell. Are we talking about logging in from an actual console or with some X terminal emulator? Have you tried 'su -' and seen if that worked? Have you tried connecting from a different computer to see if the login is triggered there?


I myself have logged in about every way possible, and /etc/profile has never once been executed. I have a custom prompt in there, but have never seen it in Gentoo because of this. (I haven't bothered putting the prompt anywhere else)
_________________
The greatest deeds are still undone, the greatest songs are still unsung...
Back to top
View user's profile Send private message
ebichu
Apprentice
Apprentice


Joined: 03 Jul 2002
Posts: 231
Location: Manchester, England

PostPosted: Mon Jul 22, 2002 6:16 pm    Post subject: Reply with quote

Try something similar to this as your ~/.xsession file:
Code:
#! /bin/bash

if [ "$SHELL" = /bin/bash -o "$SHELL" = /bin/sh ]
then
   if [ -r /etc/profile ]
   then
      . /etc/profile
   fi
   if [ "$SHELL" = /bin/bash -a -r $HOME/.bash_profile ]
   then
      . $HOME/.bash_profile
   elif [ "$SHELL" = /bin/bash -a -r $HOME/.bash_login ]
   then
      . $HOME/.bash_login
   elif [ -r $HOME/.profile ]
   then
      . $HOME/.profile
   fi
fi

if [ -n "`/etc/X11/chooser.sh`" ]
then
   exec "`/etc/X11/chooser.sh`"
else
   exec xsm
fi

_________________
Ebichu wa chiizu ga daisuki dechu!
Back to top
View user's profile Send private message
war
n00b
n00b


Joined: 27 Apr 2002
Posts: 13

PostPosted: Fri Aug 09, 2002 3:55 am    Post subject: Reply with quote

Just to be clear:

/etc/bashrc and ~/.bashrc are executed for non-login shells, like xterms

/etc/profile and ~/.bash_profile are executed for login shells--basically, when you enter a uname and password.

So, when you open an xterm, /etc/profile will NOT be executed.

I just cleared out my ~/.bashrc file and put in:

"source ~/.bash_profile"

That makes them identical for me. If you wanted to use the default system profile, make it:

"source /etc/profile"

OR, you could add your aliases and whatnot to /etc/bashrc, if you want them to be different. I always found that was just twice the work.

Man, it took me a while to figure that out, originally.... :?
Back to top
View user's profile Send private message
Naan Yaar
Bodhisattva
Bodhisattva


Joined: 27 Jun 2002
Posts: 1549

PostPosted: Fri Aug 09, 2002 4:20 am    Post subject: Reply with quote

bash actually does not deal with /etc/bashrc. Some distributions put 'source /etc/bashrc' in the skeleton .bashrc file that gets copied into user directories when a user is created.

Ideally, you want to source .bashrc from your .bash_profile file and not source /etc/profile from .bashrc. The .bashrc file should not generate any output. The skeleton .bash_profile in gentoo (/etc/skel/.bash_profile) already looks like this:
Code:

...
#This file is sourced by bash when you log in interactively.
[ -f ~/.bashrc ] && . ~/.bashrc
...


It does source the user .bashrc already. The skeleton .bashrc is empty, but you can customize it to have something like:
Code:

if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

and put in prompt customizations, aliases, etc., in /etc/bashrc. This will ensure that all shells will get these things set correctly for all users.
war wrote:

...
/etc/bashrc and ~/.bashrc are executed for non-login shells, like xterms

/etc/profile and ~/.bash_profile are executed for login shells--basically, when you enter a uname and password.

So, when you open an xterm, /etc/profile will NOT be executed.

I just cleared out my ~/.bashrc file and put in:

"source ~/.bash_profile"

That makes them identical for me. If you wanted to use the default system profile, make it:

"source /etc/profile"

OR, you could add your aliases and whatnot to /etc/bashrc, if you want them to be different. I always found that was just twice the work.

Man, it took me a while to figure that out, originally.... :?
Back to top
View user's profile Send private message
zerogeny
Tux's lil' helper
Tux's lil' helper


Joined: 17 Apr 2002
Posts: 85

PostPosted: Fri Aug 09, 2002 4:33 am    Post subject: Reply with quote

on the same topic of profile, is there a way to have 2 seperate prompt configs for a term inside X and the console because i like to have the working directory in the titlebar but this adds a tilde to the console which i dislike :)

<a href="mailto:themadmind@optushome.com.au">email</a> me with the answer
_________________
Searched the web for zerogeny.
Results 1 - 1 of 1. Search took 0.05 seconds
Back to top
View user's profile Send private message
delta407
Bodhisattva
Bodhisattva


Joined: 23 Apr 2002
Posts: 2876
Location: Chicago, IL

PostPosted: Fri Aug 16, 2002 10:40 pm    Post subject: Reply with quote

You could check the TERM variable...
_________________
I don't believe in witty sigs.
Back to top
View user's profile Send private message
taskara
Advocate
Advocate


Joined: 10 Apr 2002
Posts: 3763
Location: Australia

PostPosted: Tue Aug 27, 2002 5:22 am    Post subject: Reply with quote

hey - I seem to have stuffed my /etc/profile file - I can't execute any commands, not even ls or su or nano etc..

when I try to login or ssh in I get the following mesage:

Quote:
Last login: Tue Aug 27 15:11:32 2002 from 192.168.0.5
bash: /etc/profile: line 28: syntax error: unexpected end of file
bash: dircolors: command not found
bash-2.05a$


this is my /etc/profile file:
Code:
if [ -e "/etc/profile.env" ]
then
  source /etc/profile.env
fi

#077 would be more secure, but 022 is generally quite realistic
umask 022

if [ `/usr/bin/whoami` = 'root' ]
then
   if [ "$SHELL" = '/bin/bash' ] || [ "$SHELL" = '/bin/sh' ]
   then
      export PS1='\[\033[01;31m\]\h \[\033[01;34m\]\W \$ \[\033[00m\]'
   fi
   export PATH="/bin:/sbin:/usr/bin:/usr/sbin:${ROOTPATH}"
else
   if [ "$SHELL" = '/bin/bash' ] || [ "$SHELL" = '/bin/sh' ]
   then
      export PS1='\[\033[01;32m\]\u@\h \[\033[01;34m\]\W \$ \[\033[00m\]'
   fi
   export PATH="/bin:/usr/bin:${PATH}" fi unset ROOTPATH export
EDITOR="/usr/bin/nano"

if [ -z "$INPUTRC" -a ! -f "$HOME/.inputrc" ]
then
   export INPUTRC="/etc/inputrc"
fi


what's funny is that there is no 28th line... :? can anyone suggest what I've stuffed up - or maybe post a copy of your profile so I can check myself ? thanks!
Back to top
View user's profile Send private message
rac
Bodhisattva
Bodhisattva


Joined: 30 May 2002
Posts: 6553
Location: Japanifornia

PostPosted: Tue Aug 27, 2002 5:26 am    Post subject: Reply with quote

Try removing unwanted linebreaks - did you edit this file with nano without using the -w option?
_________________
For every higher wall, there is a taller ladder
Back to top
View user's profile Send private message
taskara
Advocate
Advocate


Joined: 10 Apr 2002
Posts: 3763
Location: Australia

PostPosted: Tue Aug 27, 2002 5:31 am    Post subject: Reply with quote

no, I always use -w option with nano, but I did make a typo when I was adding some entried for java-sdk, I went to exit and not save it, but by reflex I saved it :roll:

now I am trying to get it back to what it should be originally.. argh..
Back to top
View user's profile Send private message
rac
Bodhisattva
Bodhisattva


Joined: 30 May 2002
Posts: 6553
Location: Japanifornia

PostPosted: Tue Aug 27, 2002 5:34 am    Post subject: Reply with quote

OK, FWIW:
Code:
@@ -1,3 +1,7 @@INPUTRC="/etc/inputrc"
+# Copyright 1999-2002 Gentoo Technologies, Inc.
+# Distributed under the terms of the GNU General Public License, v2 or later
+# $Header: /home/cvsroot/gentoo-src/rc-scripts/etc/profile,v 1.12 2002/05/12 21:48:18 azarah Exp $
+
 if [ -e "/etc/profile.env" ]rofile /tmp/afo  | less
 thenmma pkg $ diff -ub /etc/profile /tmp/afo  | less
   source /etc/profile.env
@@ -18,10 +22,12 @@
    then
       export PS1='\[\033[01;32m\]\u@\h \[\033[01;34m\]\W \$ \[\033[00m\]'
    fi
-   export PATH="/bin:/usr/bin:${PATH}" fi unset ROOTPATH export
-EDITOR="/usr/bin/nano"
+   export PATH="/bin:/usr/bin:${PATH}"
+fi
+unset ROOTPATH
+export EDITOR="/usr/bin/nano"
 
-if [ -z "$INPUTRC" -a ! -f "$HOME/.inputrc" ]
-then
+if [ -z "$INPUTRC" -a ! -f "$HOME/.inputrc" ]; then
    export INPUTRC="/etc/inputrc"
 fi
+

...this was made with diff -ub.
_________________
For every higher wall, there is a taller ladder
Back to top
View user's profile Send private message
Naan Yaar
Bodhisattva
Bodhisattva


Joined: 27 Jun 2002
Posts: 1549

PostPosted: Tue Aug 27, 2002 12:14 pm    Post subject: Reply with quote

You are just missing a "fi" at the indicated line below and hence the nice, user-friendly error :).
taskara wrote:
...
Code:
...
   fi
   export PATH="/bin:/sbin:/usr/bin:/usr/sbin:${ROOTPATH}"
else
   if [ "$SHELL" = '/bin/bash' ] || [ "$SHELL" = '/bin/sh' ]
   then
      export PS1='\[\033[01;32m\]\u@\h \[\033[01;34m\]\W \$ \[\033[00m\]'
   fi
   export PATH="/bin:/usr/bin:${PATH}" fi unset ROOTPATH export
<<--- Missing a fi here
EDITOR="/usr/bin/nano"
...


what's funny is that there is no 28th line... :? can anyone suggest what I've stuffed up - or maybe post a copy of your profile so I can check myself ? thanks!
Back to top
View user's profile Send private message
taskara
Advocate
Advocate


Joined: 10 Apr 2002
Posts: 3763
Location: Australia

PostPosted: Tue Aug 27, 2002 1:06 pm    Post subject: Reply with quote

ahh thanks :) I'll try it tomorrow at work
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum