View previous topic :: View next topic |
Author |
Message |
Sivar Apprentice
Joined: 25 May 2002 Posts: 266 Location: USA
|
Posted: Sun Jul 21, 2002 12:21 am Post subject: Equivalent of /etc/profile |
|
|
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 |
|
|
Jesse Tux's lil' helper
Joined: 24 Apr 2002 Posts: 148
|
Posted: Sun Jul 21, 2002 1:07 am Post subject: |
|
|
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 |
|
|
shadow n00b
Joined: 30 Jun 2002 Posts: 16 Location: ph
|
Posted: Sun Jul 21, 2002 1:53 pm Post subject: Re: Equivalent of /etc/profile |
|
|
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 |
|
|
nbensa l33t
Joined: 10 Jul 2002 Posts: 799 Location: Buenos Aires, Argentina
|
Posted: Sun Jul 21, 2002 2:09 pm Post subject: Re: Equivalent of /etc/profile |
|
|
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 |
|
|
Jesse Tux's lil' helper
Joined: 24 Apr 2002 Posts: 148
|
Posted: Sun Jul 21, 2002 2:36 pm Post subject: |
|
|
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 |
|
|
Sivar Apprentice
Joined: 25 May 2002 Posts: 266 Location: USA
|
Posted: Sun Jul 21, 2002 3:18 pm Post subject: |
|
|
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 |
|
|
ebichu Apprentice
Joined: 03 Jul 2002 Posts: 231 Location: Manchester, England
|
Posted: Mon Jul 22, 2002 6:16 pm Post subject: |
|
|
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 |
|
|
war n00b
Joined: 27 Apr 2002 Posts: 13
|
Posted: Fri Aug 09, 2002 3:55 am Post subject: |
|
|
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 |
|
|
Naan Yaar Bodhisattva
Joined: 27 Jun 2002 Posts: 1549
|
Posted: Fri Aug 09, 2002 4:20 am Post subject: |
|
|
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 |
|
|
zerogeny Tux's lil' helper
Joined: 17 Apr 2002 Posts: 85
|
Posted: Fri Aug 09, 2002 4:33 am Post subject: |
|
|
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 |
|
|
delta407 Bodhisattva
Joined: 23 Apr 2002 Posts: 2876 Location: Chicago, IL
|
Posted: Fri Aug 16, 2002 10:40 pm Post subject: |
|
|
You could check the TERM variable... _________________ I don't believe in witty sigs. |
|
Back to top |
|
|
taskara Advocate
Joined: 10 Apr 2002 Posts: 3763 Location: Australia
|
Posted: Tue Aug 27, 2002 5:22 am Post subject: |
|
|
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 |
|
|
rac Bodhisattva
Joined: 30 May 2002 Posts: 6553 Location: Japanifornia
|
Posted: Tue Aug 27, 2002 5:26 am Post subject: |
|
|
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 |
|
|
taskara Advocate
Joined: 10 Apr 2002 Posts: 3763 Location: Australia
|
Posted: Tue Aug 27, 2002 5:31 am Post subject: |
|
|
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
now I am trying to get it back to what it should be originally.. argh.. |
|
Back to top |
|
|
rac Bodhisattva
Joined: 30 May 2002 Posts: 6553 Location: Japanifornia
|
Posted: Tue Aug 27, 2002 5:34 am Post subject: |
|
|
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 |
|
|
Naan Yaar Bodhisattva
Joined: 27 Jun 2002 Posts: 1549
|
Posted: Tue Aug 27, 2002 12:14 pm Post subject: |
|
|
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 |
|
|
taskara Advocate
Joined: 10 Apr 2002 Posts: 3763 Location: Australia
|
Posted: Tue Aug 27, 2002 1:06 pm Post subject: |
|
|
ahh thanks I'll try it tomorrow at work |
|
Back to top |
|
|
|