LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 10-20-2010, 07:32 AM   #1
Lrrr
LQ Newbie
 
Registered: Oct 2010
Posts: 5

Rep: Reputation: 4
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
 
Old 10-20-2010, 08:04 AM   #2
carltm
Member
 
Registered: Jan 2007
Location: Canton, MI
Distribution: CentOS, SuSE, Red Hat, Debian, etc.
Posts: 703

Rep: Reputation: 97
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.
 
1 members found this post helpful.
Old 10-20-2010, 08:19 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,529

Rep: Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896Reputation: 2896
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.
 
1 members found this post helpful.
Old 10-20-2010, 03:41 PM   #4
Lrrr
LQ Newbie
 
Registered: Oct 2010
Posts: 5

Original Poster
Rep: Reputation: 4
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
.bashrc / .bash_profile /etc/profile /etc/bashrc deadeyes Red Hat 2 02-13-2010 11:22 AM
Setting path: /etc/profile, /etc/bashrc or ~/.bashrc Swakoo Linux - General 1 08-07-2007 10:59 PM
.bashrc hilljockey Debian 5 06-07-2006 01:11 PM
.bashrc roofy Slackware 7 05-06-2003 01:32 PM
bashrc nobu Slackware 6 03-21-2003 10:53 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:52 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration