Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[bash] Qui n'affiche plus le user ou root.
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index French
View previous topic :: View next topic  
Author Message
d2_racing
Bodhisattva
Bodhisattva


Joined: 25 Apr 2005
Posts: 13047
Location: Ste-Foy,Canada

PostPosted: Thu Jun 16, 2005 11:19 am    Post subject: [bash] Qui n'affiche plus le user ou root. Reply with quote

Salut tout le monde, je viens de me déprendre d'un problème que j'avais depuis que les fichiers ont changés(soit la semaine dernière).

Voici ce que j'ai eu comme problème

sylvain@gentootux ~$ C'est en user

En root
gentootux ~ #

J'aime pas ça pantoute, car je sais jamais quand je suis en root.... car avant j'avais root@gentootux ~

gentootux ~ # cat /etc/profile
# /etc/profile:
# $Header: /var/cvsroot/gentoo-src/rc-scripts/etc/profile,v 1.28.4.3 2005/04/29
03:34:01 vapier Exp $
#
# That this file is used by any Bourne-shell derivative to setup the
# environment for login shells.

# Load environment settings from profile.env, which is created by
# env-update from the files in /etc/env.d
if [ -e /etc/profile.env ] ; then
. /etc/profile.env
fi

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

# Set up PATH depending on whether we're root or a normal user.
# There's no real reason to exclude sbin paths from the normal user,
# but it can make tab-completion easier when they aren't in the
# user's PATH to pollute the executable namespace.
#
# It is intentional in the following line to use || instead of -o.
# This way the evaluation can be short-circuited and calling whoami is
# avoided.
if [ "$EUID" = "0" ] || [ "$USER" = "root" ] ; then
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${ROO
TPATH}"
else
PATH="/usr/local/bin:/usr/bin:/bin:${PATH}"
fi
export PATH
unset ROOTPATH

# Extract the value of EDITOR
[ -z $EDITOR ] && EDITOR="`. /etc/rc.conf 2>/dev/null; echo $EDITOR`"
[ -z $EDITOR ] && EDITOR="/bin/nano"
export EDITOR

if [ -n "${BASH_VERSION}" ] ; then
# Newer bash ebuilds include /etc/bash/bashrc which will setup PS1
# including color. We leave out color here because not all
# terminals support it.
if [ -f /etc/bash/bashrc ] ; then
# Bash login shells run only /etc/profile
# Bash non-login shells run only /etc/bash/bashrc
# Since we want to run /etc/bash/bashrc regardless, we source it
# from here. It is unfortunate that there is no way to do
# this *after* the user's .bash_profile runs (without putting
# it in the user's dot-files), but it shouldn't make any
# difference.
. /etc/bash/bashrc
else
PS1='\u@\h \w \$ '
fi
else
# Setup a bland default prompt. Since this prompt should be useable
# on color and non-color terminals, as well as shells that don't
# understand sequences such as \h, don't put anything special in it.
PS1="`whoami`@`uname -n | cut -f1 -d.` \$ "
fi
gentootux ~ #

gentootux ~ # cat /etc/bash/bashrc
# /etc/bash.bashrc:
# $Header: /var/cvsroot/gentoo-x86/app-shells/bash/files/bashrc,v 1.6 2005/05/26 22:07:59 vapier Exp $
#
# This file is sourced by all *interactive* bash shells on startup,
# including some apparently interactive shells such as scp and rcp
# that can't tolerate any output.


# Test for an interactive shell. There is no need to set anything
# past this point for scp and rcp, and it's important to refrain from
# outputting anything in those cases.
if [[ $- != *i* ]] ; then
# Shell is non-interactive. Be done now
return
fi

# Bash won't get SIGWINCH if another process is in the foreground.
# Enable checkwinsize so that bash will check the terminal size when
# it regains control. #65623
# http://cnswww.cns.cwru.edu/~chet/bash/FAQ (E11)
shopt -s checkwinsize

# Set colorful PS1 only on colorful terminals.
# dircolors --print-database uses its own built-in database
# instead of using /etc/DIR_COLORS. Try to use the external file
# first to take advantage of user additions.
use_color=false
safe_term=${TERM//[^[:alnum:]]/.} # sanitize TERM

if [[ -f /etc/DIR_COLORS ]] ; then
grep -q "^TERM ${safe_term}" /etc/DIR_COLORS && use_color=true
elif type -p dircolors >/dev/null ; then
if dircolors --print-database | grep -q "^TERM ${safe_term}" ; then
use_color=true
fi
fi

if ${use_color} ; then
if [[ ${EUID} == 0 ]] ; then
PS1='\[\033[01;31m\]\h \[\033[01;34m\]\W \$ \[\033[00m\]'
else
PS1='\[\033[01;32m\]\u@\h \[\033[01;34m\]\w \$ \[\033[00m\]'
fi
else
if [[ ${EUID} == 0 ]] ; then
# show root@ when we don't have colors
PS1='\u@\h \W \$ '
else
PS1='\u@\h \w \$ '
fi
fi
gentootux ~ #

sylvain@gentootux ~ $ cat .bashrc
# /etc/skel/.bashrc:
# $Header: /home/cvsroot/gentoo-src/rc-scripts/etc/skel/.bashrc,v 1.8 2003/02/28 15:45:35 azarah Exp $

# This file is sourced by all *interactive* bash shells on startup. This
# file *should generate no output* or it will break the scp and rcp commands.

# colors for ls, etc.
eval `dircolors -b /etc/DIR_COLORS`
alias d="ls --color"
alias ls="ls --color=auto"
alias ll="ls --color -l"

# Change the window title of X terminals
case $TERM in
xterm*|rxvt|Eterm|eterm)
PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}\007"'
;;
screen)
PROMPT_COMMAND='echo -ne "\033_${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}\033\\"'
;;
esac

##uncomment the following to activate bash-completion:
#[ -f /etc/profile.d/bash-completion ] && source /etc/profile.d/bash-completion


gentootux ~ # echo $PSl

gentootux ~ # echo $HOSTNAME
gentootux
gentootux ~ # logout
sylvain@gentootux ~ $ echo $HOSTNAME
gentootux
sylvain@gentootux ~ $ echo $USER
sylvain
sylvain@gentootux ~ $ su -
Password:
gentootux ~ # echo $USER
root
gentootux ~ #

sylvain@gentootux ~ $ echo $BASH_VERSION
3.00.16(1)-release

sylvain@gentootux ~ $ echo $EUID
1000
sylvain@gentootux ~ $ su -
Password:
gentootux ~ # echo $EUID
0

Avec ma programmation, ça donne ceci :

sylvain@gentootux ~ $ cat /etc/bash/bashrc
# /etc/bash.bashrc:
# $Header: /var/cvsroot/gentoo-x86/app-shells/bash/files/bashrc,v 1.6 2005/05/26 22:07:59 vapier Exp $
#
# This file is sourced by all *interactive* bash shells on startup,
# including some apparently interactive shells such as scp and rcp
# that can't tolerate any output.


# Test for an interactive shell. There is no need to set anything
# past this point for scp and rcp, and it's important to refrain from
# outputting anything in those cases.
if [[ $- != *i* ]] ; then
# Shell is non-interactive. Be done now
return
fi

# Bash won't get SIGWINCH if another process is in the foreground.
# Enable checkwinsize so that bash will check the terminal size when
# it regains control. #65623
# http://cnswww.cns.cwru.edu/~chet/bash/FAQ (E11)
shopt -s checkwinsize

# Set colorful PS1 only on colorful terminals.
# dircolors --print-database uses its own built-in database
# instead of using /etc/DIR_COLORS. Try to use the external file
# first to take advantage of user additions.
use_color=false
safe_term=${TERM//[^[:alnum:]]/.} # sanitize TERM

if [[ -f /etc/DIR_COLORS ]] ; then
grep -q "^TERM ${safe_term}" /etc/DIR_COLORS && use_color=true
elif type -p dircolors >/dev/null ; then
if dircolors --print-database | grep -q "^TERM ${safe_term}" ; then
use_color=true
fi
fi

if ${use_color} ; then
if [[ ${EUID} == 0 ]] ; then
PS1='\[\033[01;31m\]\u@\h \[\033[01;34m\]\W \$ \[\033[00m\]'
echo 'passe dans root'
else
PS1='\[\033[01;32m\]\u@\h \[\033[01;34m\]\w \$ \[\033[00m\]'
echo 'passe dans user'
fi
else
if [[ ${EUID} == 0 ]] ; then
# show root@ when we don't have colors
PS1='\u@\h \W \$ '
else
PS1='\u@\h \w \$ '
fi
fi
sylvain@gentootux ~ $

sylvain@gentootux ~ $ su -
Password:
passe dans root
root@gentootux ~ #


Il manquait \u@ pour que ça revienne comme avant. Au fait, j'ai trouvé ça tout seule...car j'ai déjà fait du C sous Linux...et après tout, je code en Assembleur à la job...alors c'est pas du bash qui va m'arrêter !!!

Alors je suis bien content que ça fonctionne !!!

le truc c'est echo 'quelque chose'
et quand c'est une variable c'est echo $le_nom_de_la_variable

J'ai changé la ligne suivante :

if [[ ${EUID} == 0 ]] ; then
PS1='\[\033[01;31m\]\u@\h \[\033[01;34m\]\W \$ \[\033[00m\]'
# PS1='\[\033[01;31m\]\h \[\033[01;34m\]\W \$ \[\033[00m\]'
echo 'passe dans root'
Back to top
View user's profile Send private message
bong
Apprentice
Apprentice


Joined: 26 Oct 2004
Posts: 276
Location: Brest / Metz

PostPosted: Thu Jun 16, 2005 11:37 am    Post subject: Reply with quote

Désolé mais je comprend rien à ton post, si tu pouvais mettre les parties correspondantes a ton terminal entre des balises [ code ], ca serait beaucoup plus lisible...
Back to top
View user's profile Send private message
kernelsensei
Bodhisattva
Bodhisattva


Joined: 22 Feb 2004
Posts: 5619
Location: Woustviller/Moselle/FRANCE (49.07°N;7.02°E)

PostPosted: Thu Jun 16, 2005 11:54 am    Post subject: Reply with quote

pff c'est simple, par defaut :
# = root
$ = user

de plus quand t'es en user ya bien ton nom ... sylvain@gentootux ~$
_________________
$ ruby -e'puts " .:@BFegiklnorst".unpack("x4ax7aaX6ax5aX15ax4aax6aaX7ax2aX5aX8 \
axaX3ax8aX4ax6aX3aX6ax3ax3aX9ax4ax2aX9axaX6ax3aX2ax4ax3aX4aXaX12ax10aaX7a").join'
Back to top
View user's profile Send private message
ultrabug
Developer
Developer


Joined: 24 Jan 2005
Posts: 698
Location: Paris

PostPosted: Thu Jun 16, 2005 12:22 pm    Post subject: Reply with quote

Oui quand tu es root, tu vois toujours <machine> <rep courant> #
Back to top
View user's profile Send private message
razer
l33t
l33t


Joined: 08 Oct 2004
Posts: 893
Location: Paris - France

PostPosted: Thu Jun 16, 2005 2:22 pm    Post subject: Reply with quote

Voici une partie de mon /etc/profile, qui place en vert (défaut gentoo) l'hostname en utilisateur, et en rouge en root :
Code:

if [ `/usr/bin/whoami` = 'root' ]
then
        # Do not set PS1 for dumb terminals
        if [ "$TERM" != 'dumb'  ] && [ -n "$BASH" ]
        then
                PS1='\[\033[01;31m\][\h:\[\033[01;34m\]\w\[\033[01;31m\]]\$ \[\033[00m\]'
        fi
        export PATH="/bin:/sbin:/usr/bin:/usr/sbin:${ROOTPATH}"
else
        # Do not set PS1 for dumb terminals
        if [ "$TERM" != 'dumb'  ] && [ -n "$BASH" ]
        then
                PS1='\[\033[01;32m\][\u@\h:\[\033[01;34m\]\w]\$ \[\033[00m\]'
        fi
        export PATH="/bin:/usr/bin:${PATH}"
fi
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index French 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