changing bash prompt escape sequences

classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|

changing bash prompt escape sequences

Jay Hart-2
I use bash as my shell.

I'm trying to set the bash prompt to display:

ttyC1 user@hostname#

I've created a .bashrc in the users home directory (in this case root), and
used the following line:

PS1="\l \u@\h #"

When I login as root, or any other user for that matter, the default prompt is:

-bash-3.2#

the only way so far that I found to change the prompt is to type 'bash' at the
prompt after login. This is ok, but I know that this should work the first
time I login, without having to issue a standalone command.

I've come to the conclusion that I need to modify another file within the /etc
directory, but what?

TIA,

Jay

Reply | Threaded
Open this post in threaded view
|

Re: changing bash prompt escape sequences

Johan Beisser
On Feb 23, 2008, at 6:29 PM, Jay Hart wrote:

> I use bash as my shell.
>
> I'm trying to set the bash prompt to display:
>
> ttyC1 user@hostname#
>
> I've created a .bashrc in the users home directory (in this case  
> root), and
> used the following line:
>
> PS1="\l \u@\h #"

So, what happens when you can't log in to the system, delete the bash  
package or lose your /usr/local/ filesystem? I'd suggest not using  
that as your root login shell.

> When I login as root, or any other user for that matter, the default  
> prompt is:
>
> -bash-3.2#

Try the system bashrc, or fire use .bash_profile.

> the only way so far that I found to change the prompt is to type  
> 'bash' at the
> prompt after login. This is ok, but I know that this should work the  
> first
> time I login, without having to issue a standalone command.

 From the bash(1) 3.2 man page:

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

>
> I've come to the conclusion that I need to modify another file  
> within the /etc
> directory, but what?

So, what lead to that conclusion? Probably not the man page.

Reply | Threaded
Open this post in threaded view
|

Re: changing bash prompt escape sequences

Jay Hart-2
> On Feb 23, 2008, at 6:29 PM, Jay Hart wrote:
>
>> I use bash as my shell.
>>
>> I'm trying to set the bash prompt to display:
>>
>> ttyC1 user@hostname#
>>
>> I've created a .bashrc in the users home directory (in this case
>> root), and
>> used the following line:
>>
>> PS1="\l \u@\h #"
>
> So, what happens when you can't log in to the system, delete the bash
> package or lose your /usr/local/ filesystem? I'd suggest not using
> that as your root login shell.

I'll have to rescue the system if I can't login as root.
If I lose my /usr/local filesystem, I've probably lost the drive too.
I guess I have to ensure that I don't delete the bash package.


>
>> When I login as root, or any other user for that matter, the default
>> prompt is:
>>
>> -bash-3.2#
>
> Try the system bashrc, or fire use .bash_profile.

Created .bash_profile, same behavior.

>
>> the only way so far that I found to change the prompt is to type
>> 'bash' at the
>> prompt after login. This is ok, but I know that this should work the
>> first
>> time I login, without having to issue a standalone command.
>
>  From the bash(1) 3.2 man page:
>
>         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  behav-
>         ior.
>
>>
>> I've come to the conclusion that I need to modify another file
>> within the /etc directory, but what?
>
> So, what lead to that conclusion? Probably not the man page.
>

I've looked at or modified every file in roots and one users home directory
without having the prompt displayed upon initial login. Once I login, and run
'bash', the prompt will be displayed as I set it. This leads me to believe
that I have an initial file to set which is being read as part of the init of
the box.

Jay

Reply | Threaded
Open this post in threaded view
|

Re: changing bash prompt escape sequences

Johan Beisser
On Feb 23, 2008, at 7:35 PM, Jay Hart wrote:

>
> I've looked at or modified every file in roots and one users home  
> directory
> without having the prompt displayed upon initial login. Once I  
> login, and run
> 'bash', the prompt will be displayed as I set it. This leads me to  
> believe
> that I have an initial file to set which is being read as part of  
> the init of
> the box.

It's likely bash(1) may avoid reading roots environment. Check /etc/
profile, and read the man page on bash. It's ugly, confusing, but it  
may clear up your issues.

If it helps, you may need to make sure that your shell is invoked  
properly:

    PS1 is set and $- includes i if bash is interactive,  allowing  a
    shell script or a startup file to test this state.


I rarely (never, actually) log in as root unless the system is in  
single user mode. Even then, I don't use bash, sh(1) and ksh(1) work  
just fine. As a user, sudo(8) works better.

Reply | Threaded
Open this post in threaded view
|

Re: changing bash prompt escape sequences

Unix Fan
In reply to this post by Jay Hart-2
$ cat .bash_profile

...

export PS1="\l \u@\h #"

$



Then log back in..... this really is basic stuff.. ;)



(Use ksh, it's much better then bash... )







-Nix Fan.



Reply | Threaded
Open this post in threaded view
|

Re: changing bash prompt escape sequences

bofh-6
In reply to this post by Jay Hart-2
On Sat, Feb 23, 2008 at 10:35 PM, Jay Hart <[hidden email]> wrote:
>  I'll have to rescue the system if I can't login as root.
>  If I lose my /usr/local filesystem, I've probably lost the drive too.
>  I guess I have to ensure that I don't delete the bash package.

In UNIX, it is always recommended not to change root's shell.  This is
because, especially on commercially available systems, you have to
update the systems using whatever packages and assumptions built in.

In free UNIX systems, it is also recommended for similar reasons.  On
top of that, if you screw up, you can't call in for support so you
have to learn to know your system pretty well.

--
http://www.glumbert.com/media/shift
http://www.youtube.com/watch?v=tGvHNNOLnCk
"This officer's men seem to follow him merely out of idle curiosity."
-- Sandhurst officer cadet evaluation.
"Securing an environment of Windows platforms from abuse - external or
internal - is akin to trying to install sprinklers in a fireworks
factory where smoking on the job is permitted."  -- Gene Spafford
learn french:  http://www.youtube.com/watch?v=j1G-3laJJP0&feature=related


Reply | Threaded
Open this post in threaded view
|

Re: changing bash prompt escape sequences

scott-209
In reply to this post by Unix Fan
version a... export PS1="\l \u@\h #"

version b... export PS1="\l \u@\h \\$"

"B" changes the "#" to be either "$" or "#" per user's non-root/root status.

-----Original Message-----
From: Unix Fan <[hidden email]>
To: [hidden email]
Subject: Re: changing bash prompt escape sequences
Date: 24 Feb 2008 08:54:19 -0800
Delivered-To: [hidden email]

$ cat .bash_profile

...

export PS1="\l \u@\h #"

$



Then log back in..... this really is basic stuff.. ;)



(Use ksh, it's much better then bash... )







-Nix Fan.


Reply | Threaded
Open this post in threaded view
|

Re: changing bash prompt escape sequences

Unix Fan
In reply to this post by Jay Hart-2
scott wrote:

> version a... export PS1="\l \u@\h #"

>

> version b... export PS1="\l \u@\h \\$"

>

> "B" changes the "#" to be either "$" or "#" per user's non-root/root status.



I was just using the line they provided... it's up to them to read the manual.







-Nix Fan.



Reply | Threaded
Open this post in threaded view
|

Re: changing bash prompt escape sequences

William Boshuck
In reply to this post by bofh-6
I have seen the following sort of remarks a couple of
times this past week, yet I haven't seen them corrected.
Nick Holland is such an excellent writer that, as often
as not, you don't need to look at the sample code to
follow his advice.  That's not relevant in this case,
except insofar as I cannot understand why more people
don't spend more time with the FAQ (especially those who
offer advice).

On Sun, Feb 24, 2008 at 12:16:18PM -0500, bofh wrote:
>
> In UNIX, it is always recommended not to change root's shell.  This is
> because ...
>
> In free UNIX systems, it is also recommended for similar reasons ...

"... though there is no good reason not to in OpenBSD."

Let's save the rest of

     http://www.openbsd.org/faq/faq10.html#rootshell

for the curious reader.


(That said, I second recommendations to just use ksh.)


Reply | Threaded
Open this post in threaded view
|

Re: changing bash prompt escape sequences

Jay Hart-2
I will take your's and Nick's advice, and change root shell back to ksh.

Thanks,

Jay

> I have seen the following sort of remarks a couple of
> times this past week, yet I haven't seen them corrected.
> Nick Holland is such an excellent writer that, as often
> as not, you don't need to look at the sample code to
> follow his advice.  That's not relevant in this case,
> except insofar as I cannot understand why more people
> don't spend more time with the FAQ (especially those who
> offer advice).
>
> On Sun, Feb 24, 2008 at 12:16:18PM -0500, bofh wrote:
>>
>> In UNIX, it is always recommended not to change root's shell.  This is
>> because ...
>>
>> In free UNIX systems, it is also recommended for similar reasons ...
>
> "... though there is no good reason not to in OpenBSD."
>
> Let's save the rest of
>
>      http://www.openbsd.org/faq/faq10.html#rootshell
>
> for the curious reader.
>
>
> (That said, I second recommendations to just use ksh.)


Reply | Threaded
Open this post in threaded view
|

Re: changing bash prompt escape sequences

Tobias Ulmer
In reply to this post by William Boshuck
On Sun, Feb 24, 2008 at 04:53:35PM -0500, William Boshuck wrote:

> I have seen the following sort of remarks a couple of
> times this past week, yet I haven't seen them corrected.
> Nick Holland is such an excellent writer that, as often
> as not, you don't need to look at the sample code to
> follow his advice.  That's not relevant in this case,
> except insofar as I cannot understand why more people
> don't spend more time with the FAQ (especially those who
> offer advice).
>
> On Sun, Feb 24, 2008 at 12:16:18PM -0500, bofh wrote:
> >
> > In UNIX, it is always recommended not to change root's shell.  This is
> > because ...
> >
> > In free UNIX systems, it is also recommended for similar reasons ...
>
> "... though there is no good reason not to in OpenBSD."
>
> Let's save the rest of
>
>      http://www.openbsd.org/faq/faq10.html#rootshell
>
> for the curious reader.
>
>
> (That said, I second recommendations to just use ksh.)
>
>

While technically correct, there are usually two people/release
clever enough to have their server in some remote datacenter,
upgrade over ssh, run into some package problem, uninstall them
all to reinstall... Ooops, no more login, no more su etc.

The mailinglist archives have amusing material on this :p


Reply | Threaded
Open this post in threaded view
|

Re: changing bash prompt escape sequences

Jordi Espasa Clofent-3
In reply to this post by Unix Fan
Only for fun:

$ cat /etc/profile
# sh/ksh initialization
# add the same config is ssh access case

PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin:/usr/local/sbin:/usr/local/bin
PS1="[\u@\h] [\w] [\t]\n\$ "
HISTFILE=.ksh_history
HISTSIZE=500
CVSROOT=[hidden email]:/cvs
PKG_PATH=ftp://ftp.irisa.fr/pub/OpenBSD/4.2/packages/amd64/
TERM=vt220
export PATH PS1 HISTFILE HISTSIZE PKG_PATH CVSROOT TERM
umask 022
alias su='su -l'
alias ll='ls -lah'
alias rm='rm -i'

if [ -n "$SSH_CONNECTION" ]; then
 
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin:/usr/local/sbin:/usr/local/bin
         PS1="[\u@\h] [\w] [\t]\n\$ "
         HISTFILE=.ksh_history
         HISTSIZE=500
         CVSROOT=[hidden email]:/cvs
         PKG_PATH=ftp://ftp.irisa.fr/pub/OpenBSD/4.2/packages/amd64/
         TERM=vt220
         export PATH PS1 HISTFILE HISTSIZE PKG_PATH CVSROOT TERM
         umask 022
         alias su='su -l'
         alias ll='ls -lah'
         alias rm='rm -i'
fi

Maybe it will be useful for someone. Maybe not.

--
Thanks,
Jordi Espasa Clofent


Reply | Threaded
Open this post in threaded view
|

Re: changing bash prompt escape sequences

Jan Stary
In reply to this post by Jay Hart-2
On Feb 23 21:29:57, Jay Hart wrote:

> I use bash as my shell.
>
> I'm trying to set the bash prompt to display:
>
> ttyC1 user@hostname#
>
> I've created a .bashrc in the users home directory (in this case root), and
> used the following line:
>
> PS1="\l \u@\h #"
>
> When I login as root, or any other user for that matter, the default prompt is:
>
> -bash-3.2#
>
> the only way so far that I found to change the prompt is to type 'bash' at the
> prompt after login. This is ok, but I know that this should work the first
> time I login, without having to issue a standalone command.

Read man bash again and pay extra attention to the INVOCATION section.

         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.

See? An "interactive shell that is not a login shell". The first shell
is not the case, the second is.

> I've come to the conclusion that I need to modify another file within
> the /etc directory, but what?

You don't need to change anything under /etc
to make a modification for one given user.

(BTW, you are not "changing bash prompt escape sequences"
but changing the bash "prompt string".)

        Jan

Reply | Threaded
Open this post in threaded view
|

Re: changing bash prompt escape sequences

Giancarlo Razzolini
In reply to this post by Jay Hart-2
Jay Hart escreveu:

> I use bash as my shell.
>
> I'm trying to set the bash prompt to display:
>
> ttyC1 user@hostname#
>
> I've created a .bashrc in the users home directory (in this case root), and
> used the following line:
>
> PS1="\l \u@\h #"
>
> When I login as root, or any other user for that matter, the default prompt
is:
>
> -bash-3.2#
>
> the only way so far that I found to change the prompt is to type 'bash' at
the
> prompt after login. This is ok, but I know that this should work the first
> time I login, without having to issue a standalone command.
>
> I've come to the conclusion that I need to modify another file within the
/etc
> directory, but what?
>
> TIA,
>
> Jay
>
>
I use the following /etc/profile that will provide a prompt for various
shell's. Also set some nice variables:

export MANPAGER="/usr/bin/less"
export SVN_EDITOR="/usr/local/bin/emacs"
export PKG_PATH="ftp://ftp.openbsd.org/pub/OpenBSD/4.2/packages/i386/"

if [ "$SHELL" = "/bin/pdksh" ]; then
 PS1='! $ '
elif [ "$SHELL" = "/bin/ksh" ]; then
 PS1='\u@\h:\w\$ '
elif [ "$SHELL" = "/bin/zsh" ]; then
 PS1='%n@%m:%~%# '
elif [ "$SHELL" = "/bin/ash" ]; then
 PS1='$ '
else
 PS1='\u@\h:\w\$ '
fi

I've used to change the root shell to bash in the past. This isn't as
good as it sounds. I run into problems when upgrading. I prefer create a
 normal user with sudo privileges and this user having bash as shell.
This is much better.

My regards,
--
Giancarlo Razzolini
Linux User 172199
Red Hat Certified Engineer no:804006389722501
Moleque Sem Conteudo Numero #002
Slackware Current
OpenBSD Stable
Ubuntu 7.04 Feisty Fawn
Snike Tecnologia em Informatica
4386 2A6F FFD4 4D5F 5842  6EA0 7ABE BBAB 9C0E 6B85

[demime 1.01d removed an attachment of type application/pgp-signature which had a name of signature.asc]