Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have got it to change when I issue su - but not properly and when I issue just su
it only goes to #
and the arrow keys I can only get garbage out when I use them.
Code:
userz@voider [~]\>>$su
Password:
# ls
Desktop Downloads Pictures Templates perform
Documents Music Public Videos scripts
# ^[[A
using the up arrow to reissue the last command I get that # ^[[A
I am wanting to get a better prompt when going into su with colors (after I get this to work)
something like
Quote:
root@HostName [current directory]>>#
but even when I add this code into .bashrc (prompt code is for test purposes)
Code:
if [[ $( id -u ) -eq 0 ]] ; then
PS1="\[\e[34m\]\u\[\e[m\]@\[\e[34m\]\H\[\e[m\] [\[\e[33m\]\W\[\e[m\]]\\>>$"
else
PS1='[\u@\h \W]\<>$ '
fi
I get this
Code:
[userz@voider ~]\<>$ su
Password:
# exit
[userz@voider ~]\<>$ su -
Password:
-sh: 16: [[: not found
\[\e[1;32m\]\u [ \[\e[0m\]\w\[\e[1;32m\] ]$ \[\e[0m\]
How do I get this to work on a system wide platform?
I already know I have to use /etc/bashrc just what is it that needs to be put inside of these files?
# Setup a red prompt for root and a green one for users.
NORMAL="\[\e[0m\]"
RED="\[\e[1;31m\]"
GREEN="\[\e[1;32m\]"
if [[ $EUID == 0 ]] ; then
PS1="$RED\u [ $NORMAL\w$RED ]# $NORMAL"
else
PS1="$GREEN\u [ $NORMAL\w$GREEN ]\$ $NORMAL"
fi
They recommend doing this in /etc/profile. The root user often has history turned off for security reasons, which may be why your arrow keys don't work.
They recommend doing this in /etc/profile. The root user often has history turned off for security reasons, which may be why your arrow keys don't work.
haha actaully tried that one and it didn't work -- lead me to having to post a how to in here. thanks!
OK this is in order. System bashrc, root .bashrc, userx (me) .bashrc
Code:
[userx@voider.org ~]$ sudo cat /etc/bash/bashrc
# /etc/bash/bashrc
# Do not edit this file.
# Place your readable configs in /etc/bash/bashrc.d/*.sh
if [[ $- != *i* ]] ; then
# Shell is non-interactive. Be done now!
return
fi
if [ -d /etc/bash/bashrc.d/ ]; then
for f in /etc/bash/bashrc.d/*.sh; do
[ -r "$f" ] && . "$f"
done
unset f
fi
if [ -f /usr/bin/neofetch ]; then neofetch; fi
# Setup a red prompt for root and a green one for users.
NORMAL='\[\e[0m\]'
RED='\[\e[1;31m\]'
GREEN='\[\e[1;32m\]'
if [[ $EUID == 0 ]] ; then
PS1='$RED\u [ $NORMAL\w$RED ]# $NORMAL'
else
PS1='$GREEN\u [ $NORMAL\w$GREEN ]\$ $NORMAL'
fi
Code:
[userx@voider.org ~]$ sudo cat /root/.bashrc
# .bashrc
# If not running interactively, don't do anything
[[ $- != *i* ]] && return
alias ls='ls --color=auto'
PS1='[\u@\H \W]\$ '
Code:
[userx@voider.org ~]$ cat .bashrc
# .bashrc
# If not running interactively, don't do anything
[[ $- != *i* ]] && return
alias ls='ls --color=auto'
PS1='[\u@\H \W]\$ '
that bold line works as a system wide command, but that change prompt does not.
exit to get me back from su - to just su to echo $UID. both are coming up blank - null - empty
now when I change that test in /etc/bash/bashrc to this
Code:
# Setup a red prompt for root and a green one for users.
NORMAL='\[\e[0m\]'
RED='\[\e[1;31m\]'
GREEN='\[\e[1;32m\]'
#if [[ $EUID == 0 ]] ; then
if [[ $(id -u) -eq 0 ]] ; then
PS1='$RED\u [ $NORMAL\w$RED ]# $NORMAL'
else
PS1='$GREEN\u [ $NORMAL\w$GREEN ]\$ $NORMAL'
fi
then run this
Code:
[userx@voider.org ~]$ su
Password:
# id
uid=0(root) gid=0(root) groups=0(root)
# id -u
0
# su -
# id -u
0
#
hmmm ... seems I was not clear As per your original post, without the addition of variables, use single quotes:
Code:
if [[ $( id -u ) -eq 0 ]] ; then
PS1="\[\e[34m\]\u\[\e[m\]@\[\e[34m\]\H\[\e[m\] [\[\e[33m\]\W\[\e[m\]]\\>>$"
else
PS1='[\u@\h \W]\<>$ '
fi
# becomes
if [[ $( id -u ) -eq 0 ]] ; then
PS1='\[\e[34m\]\u\[\e[m\]@\[\e[34m\]\H\[\e[m\] [\[\e[33m\]\W\[\e[m\]]\\>>$ '
else
PS1='[\u@\h \W]\<>$ '
fi
When using double quotes you need to be aware of how many escapes you need in certain places or you get unusual responses.
This will not affect simple su, as was pointed out earlier you are not entering root's environment fully so this file you have changed will not be sourced.
hmmm ... seems I was not clear As per your original post, without the addition of variables, use single quotes:
Code:
if [[ $( id -u ) -eq 0 ]] ; then
PS1="\[\e[34m\]\u\[\e[m\]@\[\e[34m\]\H\[\e[m\] [\[\e[33m\]\W\[\e[m\]]\\>>$"
else
PS1='[\u@\h \W]\<>$ '
fi
# becomes
if [[ $( id -u ) -eq 0 ]] ; then
PS1='\[\e[34m\]\u\[\e[m\]@\[\e[34m\]\H\[\e[m\] [\[\e[33m\]\W\[\e[m\]]\\>>$ '
else
PS1='[\u@\h \W]\<>$ '
fi
When using double quotes you need to be aware of how many escapes you need in certain places or you get unusual responses.
This will not affect simple su, as was pointed out earlier you are not entering root's environment fully so this file you have changed will not be sourced.
sorry - I wiped my system and re-installed and well I figured I'd go from that linux from scratch in the system bashrc which is where this code should go to get system wide usage so I do not have to deal with my user .bashrc in this matter, yes?
if you look cose enough you'd see I replaced that " " with ' ' within the if else it is just the prompt code that is different, still regardless if I use
Code:
if [[ $( id -u ) -eq 0 ]] ; then or
if [[ $EUID == 0 ]] ; then
it does not work.
look see
Code:
if [[ $(id -u) -eq 0 ]] ; then
PS1='$RED\u [ $NORMAL\w$RED ]# $NORMAL'
else
PS1='$GREEN\u [ $NORMAL\w$GREEN ]\$ $NORMAL'
fi
single quotes are being used. still no go.
look see
Code:
GNU nano 2.7.4 File: /etc/bash/bashrc
# /etc/bash/bashrc
# Do not edit this file.
# Place your readable configs in /etc/bash/bashrc.d/*.sh
if [[ $- != *i* ]] ; then
# Shell is non-interactive. Be done now!
return
fi
if [ -d /etc/bash/bashrc.d/ ]; then
for f in /etc/bash/bashrc.d/*.sh; do
[ -r "$f" ] && . "$f"
done
unset f
fi
if [ -f /usr/bin/neofetch ]; then neofetch; fi
if [[ $( id -u ) -eq 0 ]] ; then
PS1='\[\e[34m\]\u\[\e[m\]@\[\e[34m\]\H\[\e[m\]
[\[\e[33m\]\W\[\e[m\]]\\>>$ '
else
PS1='[\u@\h \W]\<>$ '
fi
I still get this
Code:
[userx@voider.org ~]$ su
Password:
# su -
#
I think it is that the terminal starts out user, when it is still running and gets changed to root by su it does not look into that /etc/bash/basrc file again because it is already running(?) so it does not get sourced again?
You have to understand it to try it?
I ran that on Slackware.
I've had it for 8 years.
damn ... figures now that I am looking for that one post on this Debian_Chroot ... I cannot find it. SO i just stuck that in my if else in system bashrc it did nothing, so I stuck it in my ~/.bashrc and still I get nothing when changing from user to su (root) just the pound sign #
[userx@voider.org]:
[~]>>$ ps -p $$
Thank you
PID TTY TIME CMD
19323 pts/2 00:00:00 bash
[userx@voider.org]:
[~]>>$ su
Password:
# ps -p $$
PID TTY TIME CMD
15778 pts/2 00:00:00 sh
# su -
# ps -p $$
PID TTY TIME CMD
15947 pts/2 00:00:00 sh
# chsh -s /bin/bash
Changing shell for root.
Shell changed.
#
Now it is working.. just need to tweek the prompt
[root@voider.org userx]2
Now I got it.. failed to check shell for root ... always is something simple over looked item.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.