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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.