LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Understanding /etc/bashrc (https://www.linuxquestions.org/questions/linux-newbie-8/understanding-etc-bashrc-839257/)

Lrrr 10-20-2010 07:32 AM

Understanding /etc/bashrc
 
The following line is in the /etc/bashrc file. It's fedora 8. I know this is meant to configure the prompt but I don't know what the syntax is specifically doing.

PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}\007"'

I think that \033 is the ASCII character for ESC but not sure what ]0 does or anything after the HOSTNAME variable. Are these xterm control characters? All of my Google search results fail to explain it in any kind of meaningful detail.

Just trying to understand, TIA

carltm 10-20-2010 08:04 AM

What you are looking at are ANSI escape codes. They provide a way to send
formatting commands to terminals that support ANSI. Most terminal emulators
support these codes.

See this page for a list of escape codes:http://en.wikipedia.org/wiki/ANSI_escape_code.

An escape code string consists of the Escape key, the ] key, some code and a
semicolon. So \033]0; is the escape code 0 which turns off any special formatting.

grail 10-20-2010 08:19 AM

Are you sure this is the exact line? Did you copy it or type it? As it stands this does not work for me at all, however, I can tell you what most of it is doing:
Quote:

\033]0;
This should generate a colour but the format is wrong
Quote:

${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}
Everything in capitals is an environment variable.
'%%.*' says remove everything from hostname after first dot from the front.
'/#$HOME/~' says change the first value for the second if in the variable PWD

\007 in the ascii table says it is a bell so not sure about that one.

Lrrr 10-20-2010 03:41 PM

PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}\007"'


OK so \033]0; is the ANSI code to turn off attributes.

${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~} sets the prompt to the username @ host (if host is a FQDN it only uses the machine name followed by the current working directory which if that happens to be the user's home directory then display a ~.

Thanks for the help carl & grail. :hattip:


All times are GMT -5. The time now is 08:00 AM.