Solved how to change the prompt in root shell

Hi to all and happy new year!
since 14.1-RELEASE (I think) , when I am in a terminal and type "su"
the prompt change to
Code:
#
.. and before the shell whas "normal" like the normal user
how do a change it?
Thanks
 
If you only want the prompt to change, set the PS1 environment variable. Usually one of the shell's profile files does this. The default for the root shell is "/root/.profile".
E.g. you could echo "PS1='\u@\h # '" >> /root/.profile
See the sh manual page, especially this section:

Code:
   PS1       The primary prompt string, which defaults to “$ ”, unless you
               are the superuser, in which case it defaults to “# ”.  PS1 may
               include any of the following formatting sequences, which are
               replaced by the given information:

               \H      This system's fully-qualified hostname (FQDN)

               \h      This system's hostname.

               \u      User name.

               \W      The final component of the current working directory.

               \w      The entire path of the current working directory.

               \$      Superuser status.  “$” for normal users and “#” for
                       superusers.

               \\      A literal backslash.

               \[      Start of a sequence of non-printing characters (used,
                       for example, to embed ANSI CSI sequences into the
                       prompt).

               \]      End of a sequence of non-printing characters.

               The following special and non-printing characters are supported
               within the sequence of non-printing characters:

               \a      Emits ASCII BEL (0x07, 007) character.

               \e      Emits ASCII ESC (0x1b, 033) character.

               \r      Emits ASCII CR (0x0d, 015) character.

               \n      Emits CRLF sequence.
 
If you only want the prompt to change, set the PS1 environment variable. Usually one of the shell's profile files does this. The default for the root shell is "/root/.profile".
E.g. you could echo "PS1='\u@\h # '" >> /root/.profile
See the sh manual page, especially this section:

Code:
   PS1       The primary prompt string, which defaults to “$ ”, unless you
               are the superuser, in which case it defaults to “# ”.  PS1 may
               include any of the following formatting sequences, which are
               replaced by the given information:

               \H      This system's fully-qualified hostname (FQDN)

               \h      This system's hostname.

               \u      User name.

               \W      The final component of the current working directory.

               \w      The entire path of the current working directory.

               \$      Superuser status.  “$” for normal users and “#” for
                       superusers.

               \\      A literal backslash.

               \[      Start of a sequence of non-printing characters (used,
                       for example, to embed ANSI CSI sequences into the
                       prompt).

               \]      End of a sequence of non-printing characters.

               The following special and non-printing characters are supported
               within the sequence of non-printing characters:

               \a      Emits ASCII BEL (0x07, 007) character.

               \e      Emits ASCII ESC (0x1b, 033) character.

               \r      Emits ASCII CR (0x0d, 015) character.

               \n      Emits CRLF sequence.

Yes , I only want to change the prompt, but is not working..at least in Xorg(I dont know is has someting to do)
I put in
.profile and
.shrc

in both users, root and mine , the result is the same, in a X11 terminal only get a "#"
probe in lilyterm and xterm
 
But what console do you use for root?

cat /etc/passwd |grep -e root

Look at the end of the root user line, you have to have the console specified.

If you use csh, the variable to change the prompt is specified in .cshrc in the prompt variable, if you do not declare it the script generates an automatic prompt. You can declare it yourself, or directly modify it from the console, for example:

xv0: ~ # set prompt = "%N : "

I would leave you a prompt like:


If you are using sh, then you must follow the instructions of the other colleagues.
 
But what console do you use for root?

cat /etc/passwd |grep -e root

Look at the end of the root user line, you have to have the console specified.

If you use csh, the variable to change the prompt is specified in .cshrc in the prompt variable, if you do not declare it the script generates an automatic prompt. You can declare it yourself, or directly modify it from the console, for example:

xv0: ~ # set prompt = "%N : "

I would leave you a prompt like:



If you are using sh, then you must follow the instructions of the other colleagues.

I follow the advices,and works fine, but only in pure console , the prompt change when from my user change to "sh" and when become root with "su"
the problem is in X , when use for example, xterm,lilyterm,etc
 
How do you have the .xinitrc and .profile files configured?
.xinitrc
Code:
xset r on
export QT_QPA_PLATFORMTHEME=qt5ct
fvwm3

.profile
Code:
#
# .profile - Bourne Shell startup script for login shells
#
# see also sh(1), environ(7).
#

# These are normally set through /etc/login.conf.  You may override them here
# if wanted.
# PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:$HOME/bin; export PATH

# Setting TERM is normally done through /etc/ttys.  Do only override
# if you're sure that you'll never log in via telnet or xterm or a
# serial line.
# TERM=xterm;     export TERM

EDITOR=vi;       export EDITOR
PAGER=less;      export PAGER

# set ENV to a file invoked each time sh is started for interactive use.
ENV=$HOME/.shrc; export ENV

# Let sh(1) know it's at home, despite /home being a symlink.
if [ "$PWD" != "$HOME" ] && [ "$PWD" -ef "$HOME" ] ; then cd ; fi

# Query terminal size; useful for serial lines.
if [ -x /usr/bin/resizewin ] ; then /usr/bin/resizewin -z ; fi

# Display a random cookie on each login.
#if [ -x /usr/bin/fortune ] ; then /usr/bin/fortune freebsd-tips ; fi
 
But what console do you use for root?
...
Look at the end of the root user line, you have to have the console specified.
I think you mean shell, not console.

I follow the advices,and works fine, but only in pure console , the prompt change when from my user change to "sh" and when become root with "su"
the problem is in X , when use for example, xterm,lilyterm,etc
Look into xterm (and friends) starting a new login shell versus starting a subshell. That can be configured. The same applies to su / sudo / doas.

And I really hope you are not running X as root, that's a very bad idea.
 
I think you mean shell, not console.
Yes, I was referring to the shell

But I have something else to add to this, the OP says that he runs su to change to root. But he is not simulating a login, according to the su manual. To simulate a root login it is necessary to do it in the following way.

su -

That would simulate a full login, in theory it should be able to load the indicated environment variables?
 
I think you mean shell, not console.


Look into xterm (and friends) starting a new login shell versus starting a subshell. That can be configured. The same applies to su / sudo / doas.

And I really hope you are not running X as root, that's a very bad idea.

🤣 sorry..misunderstanding here , I use X as normal user and when need to do some thing as root, I open lilyterm..and type su
I use sudo,but only for shutdown fbsd as normal user
 
Back
Top