Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then 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 tried to find out some clear explanation about such a syntax (apart from the meaning of the "usual" \w,\h... codes which I already know), but I did not find anything.
More precisely, I found many documents and examples about PS1 customization, but the above syntax (particularly the ${debian_chroot:+($debian_chroot)} part) is either not used or used but not explained, as it's knowledge was taken for granted.
Can someone explain it to me or tell me where to find some clear explanation?
this is a shell parameter expansion, that can be explained as "if debian_chroot is null or unset, nothing is substituted, otherwise the expansion of $debian_chroot inside parentheses is substituted". In other words, the content of the variable debian_chroot - embedded in parentheses - is inserted into the prompt only if the variable itself is set and is not null. Otherwise a couple of empty parentheses will be displayed. You can find more details about this kind of substitution in the bash reference manual, here.
Regarding $debian_chroot it should be an alias for the chroot location, as set in /etc/debian_chroot. Not sure about this. Maybe a Debian expert might shed some light.
What is it? I saw it appears when I issue the "echo $PS1" command in a pseudo terminal (after having switched from root to user with "su user") but does not appear in ttys; why?
Finally, as it's not every day to find a... guru :], a last question: how can I, while in man pages (less), search for a word located at the beginning of a line?
Thanks a lot, I finally understood.
That kind of substitution is NOT explained in the bash man pages, is it?
Yes, it is. You can find it in man bash, section EXPANSION, subsection Parameter Expansion. The bash man page has almost the same content of the Bash Reference Manual.
What is it? I saw it appears when I issue the "echo $PS1" command in a pseudo terminal (after having switched from root to user with "su user") but does not appear in ttys; why?
Not sure about this. Please, can you elaborate the difference between tty and pts and between user and root?
Quote:
Originally Posted by armandino
Finally, as it's not every day to find a... guru :], a last question: how can I, while in man pages (less), search for a word located at the beginning of a line?
To search at the very beginning of the line, type
Code:
/^WORD_TO_SEARCH
to ignore blank spaces at the beginning:
Code:
/^ *WORD_TO_SEARCH
as for regular expressions. The only difference is that the search is case-insensitive.
Thanks for your help and courtesy.
I made some more tests. The situation seems to be as follows.
If I issue the "echo $PS1" command as "armando" user in a virtual terminal (tty) I get the expected output
I tried both logging in to Gnome as "armando" and also logging in as root, opening a pts terminal and then "becoming" armando by means of "su armando". No difference.
Indeed it looks weird. The first part does not make sense to me:
Code:
\[\e]0;
since it's not the usual color code. Anyway it looks like the PS1 variable is somehow modified by retaining the old value. Take a look at /etc/profile, /etc/bash.bashrc and eventually to your custom $HOME/.bashrc.
/etc/profile is the first configuration file sourced at login, where PS1 is set for interactive shells as
Code:
PS1='\u@\h:\w\$ '
then in /etc/bash.bashrc the debian_chroot part is appended at the beginning:
An update: looking at the Bash Prompt HOWTO, here, it looks like the escape sequence at the beginning is meant to set the terminal title. This is the reason why only pseudo-terminal allocations bring to that apparently weird prompt (actually it was my ignorance).
In the ANSI escape sequences the symbol \[ begins a sequence of non-printing characters. The symbol \] terminates it. So the part in grey:
is a non-printing sequence prepended to the actual prompt specification to set the window title. You can demonstrate it if you change one of the items, for example:
Sorry for digging up an older thread but, I believe that this portion of the PS1 value:
Code:
\[\e]0;
is a reset sequence for foreground, background, and boldness color to their default values for the "Window Title" of the pseudo-term. (Most likely specified in /etc/bash.bashrc). I believe it can be read as:
\[
{begin non-print chars}
\e]0;
{"Window Title" color and boldness default}
\u@\h: \w\a\]
{Set term title as - $USER@$HOSTNAME: $PWD#}
This is all kind of hazed speculation seeing as my days 'beautifying' my Xterm are long gone.
Taken from an answer on the Stackexchange website titled: $PS1 on Ubuntu VM does not match actual prompt
This explains pretty much all of it, but I still don't understand the purpose of the bell character (/a). EDIT: Answered my own question. Information added. See following 2 posts for details.
The default $PS1 in Ubuntu consists of three parts:
\[\e]0;\u@\h: \w\a\]
This is an escape sequence which will set the terminal title text to $USER@$HOST: $PWD.
\[ and \] indicate the beginning and end of a sequence of non-printing characters.
\e is an ASCII escape character.
]0; is the specific escape sequence to set the terminal icon and title in xterm compatible terminals
\u expands to the username of the current user.
@ is a literal @.
\h expands to the hostname.
: is a literal colon character.
\w expands to the current working directory.
\a is an ASCII bell character. In this case, it separates the terminal title from the terminal prompt.
${debian_chroot:+($debian_chroot)}
If you're in a chroot environment, this will expand to the name of the chroot in parentheses.
${var:+OTHER} evaluates to $OTHER if var is set, otherwise as null string. $debian_chroot is a variable initalized in /etc/bash.bashrc to the contents of the file /etc/debian_chroot. Thus if your chroot environment includes this file, the prompt will include the contents of that file as an indication for which chroot the shell currently operates in.
\u@\h:\w\$
This is the actual prompt you typically see.
\u, @, \h, :, \w are as above.
\$ expands to a number sign # if the effective uid is zero (i.e. user is root), otherwise it expands to a dollar sign $.
Last edited by ElementaryOS, DearWatson; 07-19-2015 at 04:08 PM.
Reason: Answered my own question, edited to append the information.
This triggers the "bell" sound in the internal speaker.
You almost certainly have this disabled -- to hear it run:
Code:
modprobe pcspkr
xset b
amixer set 'Beep' 100% unmute # pure ALSA only, for a Pulseaudio systems try: amixer -D pulse set 'Beep' 100% unmute
echo -e '\a'
EDIT: Nice necrobump BTW
Last edited by Head_on_a_Stick; 07-19-2015 at 03:00 PM.
Reason: typo
This triggers the "bell" sound in the internal speaker.
You almost certainly have this disabled -- to hear it run:
Code:
modprobe pcspkr
xset b
amixer set 'Beep' 100 unmute # pure ALSA only, for a Pulseaudio systems try: amixer -D pulse set 'Beep' 100% unmute
echo -e '\a'
EDIT: Nice necrobump BTW
Well, yes and no. Turns out I answered my own question. From my research, the bell character (in this instance, /a) was ORIGINALLY used for an audible beep or a screen flash (visual bell). In modern usage it apparently is also used in other ways.
After experimenting with the PS1 variable myself, I determined that in this case the bell character (/a) separates the shell title from the shell prompt.
Believe it or not I created an account specifically to post to this thread. Being a super-noob, everything I know has been researched myself... so I figured I'd share the love 'n' learnin' . Please excuse the excessive formatting, I only mean to make it easier for those that just want the 'meat' of the information.
Last edited by ElementaryOS, DearWatson; 07-19-2015 at 08:46 PM.
Reason: Incorrect information removed
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.