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-11-2010, 12:45 PM
Jon Dowland
 
Default Where is Bash Prompt Set??

On Wed, Feb 10, 2010 at 09:47:56PM -0600, Stan Hoeppner
wrote:
> 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.

The subtlty of the difference depends on the length of your
prompt. With a one character prompt, the difference is
glaring - 100% of the string. I tend to colour the root
prompt differently to make it even more obvious.

> 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.

I've never met a bash that displays anything other than '#'
for '$' in PS1. Can you give an example of one that does?

In terms of other shells, '#' is so common that one can
reasonably expect a reader to understand what it is trying
to denote. If in doubt, be explicit in your preamble.

Alas I do not have immediate access to esoteric UNIX systems
anymore, but a quick check of bash, zsh, csh, tcsh, ksh,
posh, dash, psh with Debian indicates that psh and sash do
not use '#' ('%' and '>' respectively); sh, csh,
bash, tcsh and ksh on Solaris all use '#'.


--
Jon Dowland
 
Old 02-11-2010, 01:49 PM
Scott
 
Default Where is Bash Prompt Set??

Apologies that this won't be properly threaded, but I just got my
subscription problems solved.

I am the OP on this thread, and have read the replies in the archive.
Looking at the bash manual I see that, for a login shell, /etc/profile
is sourced, and then ~/.bash_profile, whereas for an interactive
non-login shell, ~/.bashrc is sourced. That makes sense, so if one
wants the same prompt in both situations, just set it in .bashrc and
have .bash_profile source that.

BUT, it doesn't answer my other question: When root logs in, his
.bashrc *is* getting sourced! I thought perhaps root had a
.bash_profile set up to do so, but this is not the case. Root has no
profile. So can anyone explain the difference here?

Scott Swanson
--
Hain't we got all the fools in town on our side? And hain't that a big
enough majority in any town?
-- Mark Twain, "Huckleberry Finn"


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

On 11/02/10, Jon Dowland (jmtd@debian.org) wrote:

| ...
| I've never met a bash that displays anything other than '#'
| for '$' in PS1. Can you give an example of one that does?

From .bashrc:

# root; red
#export PS1='[33[0;31mu@w# ]'
# sid: green
export PS1='[33[0;32mu@w$ ]'
# magenta
#export PS1='[33[0;35mu@w$ ]'
# yellow
#export PS1='[33[0;33mu@w$ ]'
# blue
#export PS1='[33[0;34mu@w$ ]'
# cyan
#export PS1='[33[0;36mu@w$ ]'

--
JohnRChamplin@columbus.rr.com
================================================== ==
GPG key 1024D/99421A63 2005-01-05
EE51 79E9 F244 D734 A012 1CEC 7813 9FE9 9942 1A63
gpg --keyserver subkeys.pgp.net --recv-keys 99421A63
 
Old 02-11-2010, 04:27 PM
"Boyd Stephen Smith Jr."
 
Default Where is Bash Prompt Set??

On Thursday 11 February 2010 11:16:15 John wrote:
> On 11/02/10, Jon Dowland (jmtd@debian.org) wrote:
> | I've never met a bash that displays anything other than '#'
> | for '$' in PS1. Can you give an example of one that does?
>
> From .bashrc:
>
> # root; red
> #export PS1='[33[0;31mu@w# ]'
> # sid: green
> export PS1='[33[0;32mu@w$ ]'
> # magenta
> #export PS1='[33[0;35mu@w$ ]'
> # yellow
> #export PS1='[33[0;33mu@w$ ]'
> # blue
> #export PS1='[33[0;34mu@w$ ]'
> # cyan
> #export PS1='[33[0;36mu@w$ ]'

None of those are examples of what Jon D. requested. Your example would have
to use '$' (not just '$') in PS1.
--
Boyd Stephen Smith Jr. ,= ,-_-. =.
bss@iguanasuicide.net ((_/)o o(\_))
ICQ: 514984 YM/AIM: DaTwinkDaddy `-'(. .)`-'
http://iguanasuicide.net/ \_/
 
Old 02-11-2010, 04:53 PM
Tony van der Hoff
 
Default Where is Bash Prompt Set??

On 11/02/10 17:16, John wrote:

On 11/02/10, Jon Dowland (jmtd@debian.org) wrote:

| ...
| I've never met a bash that displays anything other than '#'
| for '$' in PS1. Can you give an example of one that does?

From .bashrc:

# root; red
#export PS1='[33[0;31mu@w# ]'


Very useful thread, thank you all.

So, I've set my PS1 in /root/.bashrc as suggested.
From my user shell, I do 'su', and the prompt, and everything following
is in red - good!

CTRL-D returns me to my user shell, and everything is still red - bad!

So, I figured that export PS1='[33[0;31mu@w$33[0;30m ]' would
return it back to black after the prompt - which it does, and I can live
with that, but ideally, I'd like to save away the present colour, and
restore it.

Can anyone suggest how to do that?

PS - where are these escape sequences documented, please?


--
Tony van der Hoff | mailto:tony@vanderhoff.org
Buckinghamshire, England |


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

On 11/02/10, Tony van der Hoff (tony@vanderhoff.org) wrote:

| ...
| PS - where are these escape sequences documented, please?

http://www.linuxfocus.org/English/May2004/article335.shtml

--
JohnRChamplin@columbus.rr.com
================================================== ==
GPG key 1024D/99421A63 2005-01-05
EE51 79E9 F244 D734 A012 1CEC 7813 9FE9 9942 1A63
gpg --keyserver subkeys.pgp.net --recv-keys 99421A63
 
Old 02-12-2010, 03:03 AM
Stan Hoeppner
 
Default Where is Bash Prompt Set??

Jon Dowland put forth on 2/11/2010 7:45 AM:

> to denote. If in doubt, be explicit in your preamble.

This was my point. However, for a document writer, doubt, stupidity, not enough
coffee in the readers' belly and thus not enough caffeine in the brain should
always be assumed. Thus, it should always clearly be stated in the document
when a command example needs to be executed as root or with sudo privileges,
regardless of what characters are present or not in the example prompt. This is
technical writing 101: always be explicit, verbose, when dealing with example
commands readers will be executing on their machines.

--
Stan


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

Tony van der Hoff put forth on 2/11/2010 11:53 AM:

> So, I've set my PS1 in /root/.bashrc as suggested.
> From my user shell, I do 'su', and the prompt, and everything following
> is in red - good!
> CTRL-D returns me to my user shell, and everything is still red - bad!

CTRL-D is new to me. Thanks for the trick.

> So, I figured that export PS1='[33[0;31mu@w$33[0;30m ]' would
> return it back to black after the prompt - which it does, and I can live
> with that, but ideally, I'd like to save away the present colour, and
> restore it.
> Can anyone suggest how to do that?

It works for me. I use this:

/root/.bashrc
export PS1="$(tput setaf 1)[T]$(tput setaf 1)[u@h]$(tput sgr0)w$ "

/home/stan/.bashrc
if [ "$PS1" ]; then
PS1="$(tput setaf 2)[T]$(tput setaf 2)[u@h]$(tput sgr0)w$ "
fi

When I from su the prompt color is back to that defined directly above for user
stan.

> PS - where are these escape sequences documented, please?

I use this as my reference. Not a bash manual, but works for me:

http://news.softpedia.com/news/How-to-Customize-the-Shell-Prompt-40033.shtml

--
Stan


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 02-13-2010, 01:15 PM
Tony van der Hoff
 
Default Where is Bash Prompt Set??

On 12/02/10 04:20, Stan Hoeppner wrote:
> Tony van der Hoff put forth on 2/11/2010 11:53 AM:
>

Thanks for your help, everyone.

--
Tony van der Hoff | mailto:tony@vanderhoff.org
Buckinghamshire, England |


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

On Thu, Feb 11, 2010 at 10:20:47PM -0600, Stan Hoeppner wrote:
> It works for me. I use this:
>
> /root/.bashrc
> export PS1="$(tput setaf 1)[T]$(tput setaf 1)[u@h]$(tput sgr0)w$ "
>
> /home/stan/.bashrc
> if [ "$PS1" ]; then
> PS1="$(tput setaf 2)[T]$(tput setaf 2)[u@h]$(tput sgr0)w$ "
> fi

The problem with that is, you are only invoking it on login.
This together with

> CTRL-D is new to me. Thanks for the trick.

suggests you are logging from your root user back into your
normal user, never logging out of these shells, and the
older shell processes are hanging around, like this:

$ ps
PID TTY TIME CMD
18672 pts/0 00:00:00 bash
18689 pts/0 00:00:00 ps
$ su -
Password:
ra:~# ps
PID TTY TIME CMD
18690 pts/0 00:00:00 su
18700 pts/0 00:00:00 bash
18704 pts/0 00:00:00 ps
ra:~# su - jon
Password:
$ ps
PID TTY TIME CMD
18672 pts/0 00:00:00 bash
18705 pts/0 00:00:00 su
18720 pts/0 00:00:00 bash
18739 pts/0 00:00:00 ps

What you really want to do is execute some code as root on
logout. One hacky way to do it is to call reset in root's
logout script:

$ sudo su -
root promptroot@~# cat .bash_login
export PS1='root prompt[33[0;31mu@w$33[0;30m ]'
root promptroot@~# cat .bash_logout
reset
root promptroot@~#
<screen clears>
$

This is a bit slow, mind, if you really want to change the
text colour for the root user then you should "unwind" the
control characters instead by preserving the older PS1 and
keeping track of which control sequences you've "opened":

~root/.bash_login:
export OLDPS1="$PS1"
export PS1="whatever you want"
~root/.bash_logout:
echo "control chars that reset the text colours"
export PS1="$OLDPS1"

--
Jon Dowland
 

Thread Tools




All times are GMT. The time now is 04:30 PM.

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