FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Debian > Debian User

 
 
LinkBack Thread Tools
 
Old 02-08-2010, 10:21 PM
Scott
 
Default Where is Bash Prompt Set??

Hi, I'm new to debian, but not to linux. (experimenting with lenny...)

This is the question I asked myself while seeing various prompts after
I thought I had customised them. Near as I can tell, there are three
different scripts which fiddle with the default bash prompt:

/etc/profile
/etc/bashrc
~/.bashrc

I edited each one to replace the setting of PS1 with something like:

PS1="<name of file>:$PS1"

Now, logging in in different ways as different users:

Regular user on ttyn:
etc/profile:bash-3.2$

Root user on ttyn:
~/.bashrc:etc/profile:-bash-3.2#

{why does root's bashrc get sourced, but not user's?}

************************************************** **************************

Regular user in emacs shell:
~/.bashrc(nocolor):etc/bashrc:bash-3.2$

Root in emacs shell:
~/.bashrc:etc/bashrc:~/.bashrc:etc/profile:bash-3.2#

{why is root's .bashrc read twice? Why no leading - on original
root prompt? Why does /etc/profile get sourced for root but not
for user?}

************************************************** **************************

Regular user in xterm:
~/.bashrc(xterm):~/.bashrc(nocolor):etc/bashrc:bash-3.2$

Root in xterm:
~/.bashrc:etc/bashrc:~/.bashrc:etc/bashrc:bash-3.2#

{I guess no questions here, other than, again, why does root's
.bashrc get sourced two different times??}

If these aren't completely stupid questions, can anyone shed some
light?

TIA,
Scott Swanson


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 02-08-2010, 11:01 PM
"Boyd Stephen Smith Jr."
 
Default Where is Bash Prompt Set??

On Monday 08 February 2010 17:21:38 Scott wrote:
> Hi, I'm new to debian, but not to linux. (experimenting with lenny...)
>
> This is the question I asked myself while seeing various prompts after
> I thought I had customised them. Near as I can tell, there are three
> different scripts which fiddle with the default bash prompt:
>
> /etc/profile
> /etc/bashrc
> ~/.bashrc

You forgot ~/.bash_profile. It is recommended that ~/.bash_profile source
~/.bashrc, but it is not required.

> {why is root's .bashrc read twice? Why no leading - on original
> root prompt? Why does /etc/profile get sourced for root but not
> for user?}

PS1 is normally exported I think, and .bashrc might be read by a subshell.
For example, a process tree like:
"/sbin/login"
+"-/bin/bash"
+"/usr/bin/emacs"
+"/bin/bash"

Might send up reading ~/.bashrc twice.
--
Boyd Stephen Smith Jr. ,= ,-_-. =.
bss@iguanasuicide.net ((_/)o o(\_))
ICQ: 514984 YM/AIM: DaTwinkDaddy `-'(. .)`-'
http://iguanasuicide.net/ \_/
 
Old 02-08-2010, 11:10 PM
Stan Hoeppner
 
Default Where is Bash Prompt Set??

Scott put forth on 2/8/2010 5:21 PM:
> Hi, I'm new to debian, but not to linux. (experimenting with lenny...)
>
> This is the question I asked myself while seeing various prompts after
> I thought I had customised them. Near as I can tell, there are three
> different scripts which fiddle with the default bash prompt:
>
> /etc/profile
> /etc/bashrc
> ~/.bashrc

.bashrc works for me for both root and users. I used these docs as a spring board:
http://news.softpedia.com/news/How-to-Customize-the-Shell-Prompt-40033.shtml

I don't use desktop Linux. My Lenny servers are basically headless (KVM). I
haven't tested these .bashrc's at the console yet. These bash prompt tweaks
work well within Win32 Putty SSH sessions. Logging in as me and doing an SU
instantly changes the prompt, and exiting SU back to my user changes the prompt
back to the user's .bashrc prompt. I have run into only one problem with my
prompts and that is extremely long commands that wrap. Using up arrow for
previous command gets screwed up for previous wrapped commands. Other than
that, works great. I've got root's prompt in all red up to the path which is
standard white, so there's never any doubt I'm in SU. I've got users' prompts
in green, also with paths in white. I really like the prompts I came up with.
Also, I've always _hated_ that # for root's prompt, so I killed it and use a $
now. No need for it since root is now all red.

---------------------------------------------------------------------------
[05:53:41][root@greer]~$ cat .bashrc
# ~/.bashrc: executed by bash(1) for non-login shells.

# export PS1='u@h:w$ '
export PS1="$(tput setaf 1)[T]$(tput setaf 1)[u@h]$(tput sgr0)w$ "
umask 022

# You may uncomment the following lines if you want `ls' to be colorized:
export LS_OPTIONS='--color=auto'
eval `dircolors`
alias ls='ls $LS_OPTIONS'
alias ll='ls $LS_OPTIONS -l'
# alias la='ls $LS_OPTIONS -lah'
alias la='ls $LS_OPTIONS -lah --group-directories-first'
#
# Some more alias to avoid making mistakes:
# alias rm='rm -i'
# alias cp='cp -i'
# alias mv='mv -i'

CONCURRENCY_LEVEL=3

---------------------------------------------------------------------------
[05:54:18][root@greer]~$ cat /home/stan/.bashrc
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples

# If running interactively, then:
if [ "$PS1" ]; then

# don't put duplicate lines in the history. See bash(1) for more options
# export HISTCONTROL=ignoredups

# enable color support of ls and also add handy aliases
eval `dircolors`
alias ls='ls --color=auto'
alias dir='ls --color=auto --format=vertical'
alias vdir='ls --color=auto --format=long'

# some more ls aliases
alias ll='ls -l'
alias la='ls --group-directories-first -lah'
alias l='ls -CF'

# set a fancy prompt
# PS1='u@h:w$ '
PS1="$(tput setaf 2)[T]$(tput setaf 2)[u@h]$(tput sgr0)w$ "

# If this is an xterm set the title to user@host:dir
#case $TERM in
#xterm*)
# PROMPT_COMMAND='echo -ne "33]0;${USER}@${HOSTNAME}: ${PWD}07"'
# ;;
#*)
# ;;
#esac

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc).
#if [ -f /etc/bash_completion ]; then
# . /etc/bash_completion
#fi
fi

--
Stan


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 02-09-2010, 10:51 AM
Clive Standbridge
 
Default Where is Bash Prompt Set??

> Hi, I'm new to debian, but not to linux. (experimenting with lenny...)
>
> This is the question I asked myself while seeing various prompts after
> I thought I had customised them. Near as I can tell, there are three
> different scripts which fiddle with the default bash prompt:
>
> /etc/profile
> /etc/bashrc

I think that should be /etc/bash.bashrc

> ~/.bashrc

Other files which may be sourced include ~/.bash_profile,
~/.bash_login, ~/.profile, and whatever $BASH_ENV or $ENV contains.

The INVOCATION section of the bash man page explains all.


--
Cheers,
Clive


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 02-09-2010, 04:09 PM
Johannes Wiedersich
 
Default Where is Bash Prompt Set??

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Stan Hoeppner wrote:
> Also, I've always _hated_ that # for root's prompt, so I killed it and use a $
> now. No need for it since root is now all red.

FWIW, if I document my work, eg. by copy-pasting the command into a
doc-file, the color information is lost. IMHO it is therefore usefull to
have a different prompt for root. YMMV, of course.

Just my humble 2ct.

- --
Johannes

In questions of science, the authority of a thousand is not worth the
humble reasoning of a single individual.
- - Galileo Galilei, physicist and astronomer (1564-1642)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAktxlrwACgkQC1NzPRl9qEUNDwCdGnD3m/+pJGfQ03noerHlOZkV
i+sAnjkq8aJTpxS/wTwFphV15RHIqVoC
=+oec
-----END PGP SIGNATURE-----


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 02-10-2010, 04:22 AM
Stan Hoeppner
 
Default Where is Bash Prompt Set??

Johannes Wiedersich put forth on 2/9/2010 11:09 AM:
> Stan Hoeppner wrote:
>> Also, I've always _hated_ that # for root's prompt, so I killed it and use a $
>> now. No need for it since root is now all red.
>
> FWIW, if I document my work, eg. by copy-pasting the command into a
> doc-file, the color information is lost. IMHO it is therefore usefull to
> have a different prompt for root. YMMV, of course.
>
> Just my humble 2ct.

Maybe you misunderstood my example shell prompt code. Or maybe I'm just not
understanding what you're saying. Here, copy/pasted from a Putty terminal
session. Not a doc-file, but demonstrates your example nonetheless.

[11:14:14][stan@greer]/etc/postfix$
[11:16:09][root@greer]/etc/postfix$

There. No color. Root does has a different prompt. The prompt says "root"
instead of "user". What about your concern am I missing?

--
Stan


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 02-10-2010, 05:17 AM
Tom Furie
 
Default Where is Bash Prompt Set??

On Tue, Feb 09, 2010 at 11:22:03PM -0600, Stan Hoeppner wrote:

> Maybe you misunderstood my example shell prompt code. Or maybe I'm just not
> understanding what you're saying. Here, copy/pasted from a Putty terminal
> session. Not a doc-file, but demonstrates your example nonetheless.
>
> [11:14:14][stan@greer]/etc/postfix$
> [11:16:09][root@greer]/etc/postfix$
>
> There. No color. Root does has a different prompt. The prompt says "root"
> instead of "user". What about your concern am I missing?

I think the point is that it's a lot easier to overlook "root" buried
somewhere in the middle of a long prompt than it is to overlook a "#"
right next to the cursor.

Cheers,
Tom

--
Real Users never use the Help key.
 
Old 02-10-2010, 08:30 AM
Johannes Wiedersich
 
Default Where is Bash Prompt Set??

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Stan Hoeppner wrote:
> Maybe you misunderstood my example shell prompt code.

> [11:14:14][stan@greer]/etc/postfix$
> [11:16:09][root@greer]/etc/postfix$
>
> There. No color. Root does has a different prompt. The prompt says "root"
> instead of "user". What about your concern am I missing?

Well, never mind. It's really cool that anyone can customize to his or
her liking.

For my purposes, I usually just document the command and the '#', not
the whole prompt. As I wrote, YMMV.

Have fun!

- --
Johannes

In questions of science, the authority of a thousand is not worth the
humble reasoning of a single individual.
- - Galileo Galilei, physicist and astronomer (1564-1642)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAktyfLwACgkQC1NzPRl9qEWBlwCfR/0cdXqCcC5SChqyPNM0aMis
xjAAnj3+xtXMJz6Su3Z6YnaaGbYN7/8T
=PXE8
-----END PGP SIGNATURE-----


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 02-10-2010, 03:49 PM
Jon Dowland
 
Default Where is Bash Prompt Set??

On Wed, Feb 10, 2010 at 06:17:20AM +0000, Tom Furie wrote:
> I think the point is that it's a lot easier to overlook "root" buried
> somewhere in the middle of a long prompt than it is to overlook a "#"
> right next to the cursor.

Stan's example is trivially fixed by replacing the static
'$' with '$' (and ensuring the string remains
single-quoted)
 
Old 02-11-2010, 02:47 AM
Stan Hoeppner
 
Default Where is Bash Prompt Set??

Tom Furie put forth on 2/10/2010 12:17 AM:
> On Tue, Feb 09, 2010 at 11:22:03PM -0600, Stan Hoeppner wrote:
>
>> Maybe you misunderstood my example shell prompt code. Or maybe I'm just not
>> understanding what you're saying. Here, copy/pasted from a Putty terminal
>> session. Not a doc-file, but demonstrates your example nonetheless.
>>
>> [11:14:14][stan@greer]/etc/postfix$
>> [11:16:09][root@greer]/etc/postfix$
>>
>> There. No color. Root does has a different prompt. The prompt says "root"
>> instead of "user". What about your concern am I missing?
>
> I think the point is that it's a lot easier to overlook "root" buried
> somewhere in the middle of a long prompt than it is to overlook a "#"
> right next to the cursor.

An author of technical documentation should never rely on the ability of the
reader to pick up on the subtle one character difference of $ or # in a command
line example. Any command run by root should always be identified as such with
additional text. Additionally, bash is the default shell on many *nix
variants/distros, and far from all of them use # trailing the prompt to denote
root is currently logged into the shell. If one is writing cross-platform or
generic documentation, again, one should never rely on # or $ conveying to the
reader what user is logged into the shell. Always be explicit when teaching the
command line.

--
Stan



--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 

Thread Tools




All times are GMT. The time now is 02:57 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org