Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html class="client-js" dir="ltr" lang="en"><head>
- <meta http-equiv="content-type" content="text/html; charset=UTF-8">
- <meta charset="UTF-8">
- <title>Changing bash prompt - Linux Shell Scripting Tutorial - A Beginner's handbook</title>
- <script async="" src="Changing%20bash%20prompt%20-%20Linux%20Shell%20Scripting%20Tutorial%20-%20A%20Beginner's%20handbook_files/analytics.js"></script><script type="text/javascript">document.documentElement.className = document.documentElement.className.replace( /(^|\s)client-nojs(\s|$)/, "$1client-js$2" );</script>
- <script type="text/javascript">(window.RLQ=window.RLQ||[]).push(function(){mw.config.set({"wgCanonicalNamespace":"","wgCanonicalSpecialPageName":false,"wgNamespaceNumber":0,"wgPageName":"Changing_bash_prompt","wgTitle":"Changing bash prompt","wgCurRevisionId":3552,"wgRevisionId":3552,"wgArticleId":339,"wgIsArticle":true,"wgIsRedirect":false,"wgAction":"view","wgUserName":null,"wgUserGroups":["*"],"wgCategories":["Variables and Quoting","Commands"],"wgBreakFrames":false,"wgPageContentLanguage":"en","wgPageContentModel":"wikitext","wgSeparatorTransformTable":["",""],"wgDigitTransformTable":["",""],"wgDefaultDateFormat":"dmy","wgMonthNames":["","January","February","March","April","May","June","July","August","September","October","November","December"],"wgMonthNamesShort":["","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],"wgRelevantPageName":"Changing_bash_prompt","wgRelevantArticleId":339,"wgRequestId":"59a30e7eb75b34b330f7dcef","wgIsProbablyEditable":false,"wgRelevantPageIsProbablyEditable":false,"wgRestrictionEdit":[],"wgRestrictionMove":[],"wgPreferredVariant":"en","wgMFExpandAllSectionsUserOption":true,"wgMFEnableFontChanger":true,"wgMFDisplayWikibaseDescriptions":{"search":false,"nearby":false,"watchlist":false,"tagline":false},"wgWikiEditorEnabledModules":[]});mw.loader.state({"site.styles":"ready","noscript":"ready","user.styles":"ready","user":"ready","site":"ready","user.options":"ready","user.tokens":"loading","ext.pygments":"ready","ext.cite.styles":"ready","mediawiki.legacy.shared":"ready","mediawiki.legacy.commonPrint":"ready","mediawiki.sectionAnchor":"ready","mediawiki.skinning.interface":"ready","skins.vector.styles":"ready"});mw.loader.implement("user.tokens@0q07yft",function($,jQuery,require,module){/*@nomin*/mw.user.tokens.set({"editToken":"+\\","patrolToken":"+\\","watchToken":"+\\","csrfToken":"+\\"});
- });mw.loader.load(["ext.cite.a11y","mediawiki.page.startup","mediawiki.user","mediawiki.hidpi","mediawiki.page.ready","mediawiki.toc","mediawiki.searchSuggest","skins.vector.js"]);});</script>
- <link rel="stylesheet" href="Changing%20bash%20prompt%20-%20Linux%20Shell%20Scripting%20Tutorial%20-%20A%20Beginner's%20handbook_files/load.css">
- <script async="" src="Changing%20bash%20prompt%20-%20Linux%20Shell%20Scripting%20Tutorial%20-%20A%20Beginner's%20handbook_files/load.php" type="text/javascript"></script>
- <style>
- .cite-accessibility-label{ top:-99999px;clip:rect(1px 1px 1px 1px); clip:rect(1px,1px,1px,1px); position:absolute !important;padding:0 !important;border:0 !important;height:1px !important;width:1px !important; overflow:hidden}
- .suggestions{overflow:hidden;position:absolute;top:0;left:0;width:0;border:0;z-index:1099;padding:0;margin:-1px 0 0 0}.suggestions-special{position:relative;background-color:#fff;cursor:pointer;border:1px solid #a2a9b1;margin:0;margin-top:-2px;display:none;padding:0.25em 0.25em;line-height:1.25em}.suggestions-results{background-color:#fff;cursor:pointer;border:1px solid #a2a9b1;padding:0;margin:0}.suggestions-result{color:#000;margin:0;line-height:1.5em;padding:0.01em 0.25em;text-align:left; overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.suggestions-result-current{background-color:#2a4b8d;color:#fff}.suggestions-special .special-label{color:#72777d;text-align:left}.suggestions-special .special-query{color:#000;font-style:italic;text-align:left}.suggestions-special .special-hover{background-color:#c8ccd1}.suggestions-result-current .special-label,.suggestions-result-current .special-query{color:#fff}.highlight{font-weight:bold}
- @media screen {
- .tochidden,.toctoggle{-moz-user-select:none;-webkit-user-select:none;-ms-user-select:none;user-select:none}.toctoggle{font-size:94%}}
- @media print {
- .toc.tochidden,.toctoggle{display:none}}</style><style>
- .suggestions a.mw-searchSuggest-link,.suggestions a.mw-searchSuggest-link:hover,.suggestions a.mw-searchSuggest-link:active,.suggestions a.mw-searchSuggest-link:focus{color:#000;text-decoration:none}.suggestions-result-current a.mw-searchSuggest-link,.suggestions-result-current a.mw-searchSuggest-link:hover,.suggestions-result-current a.mw-searchSuggest-link:active,.suggestions-result-current a.mw-searchSuggest-link:focus{color:#fff}.suggestions a.mw-searchSuggest-link .special-query{ overflow:hidden;text-overflow:ellipsis;white-space:nowrap}</style><meta name="ResourceLoaderDynamicStyles" content="">
- <link rel="stylesheet" href="Changing%20bash%20prompt%20-%20Linux%20Shell%20Scripting%20Tutorial%20-%20A%20Beginner's%20handbook_files/load_002.css">
- <meta name="generator" content="MediaWiki 1.31.0">
- <link rel="shortcut icon" href="https://bash.cyberciti.biz/favicon.ico">
- <link rel="search" type="application/opensearchdescription+xml" href="https://bash.cyberciti.biz/wiki/opensearch_desc.php" title="Linux Shell Scripting Tutorial - A Beginner's handbook (en)">
- <link rel="EditURI" type="application/rsd+xml" href="https://bash.cyberciti.biz/wiki/api.php?action=rsd">
- <link rel="license" href="https://creativecommons.org/licenses/by-nc-sa/3.0/">
- <link rel="alternate" type="application/atom+xml" title="Linux Shell Scripting Tutorial - A Beginner's handbook Atom feed" href="https://bash.cyberciti.biz/wiki/index.php?title=Special:RecentChanges&feed=atom">
- <!--[if lt IE 9]><script src="/wiki/load.php?debug=false&lang=en&modules=html5shiv&only=scripts&skin=vector&sync=1"></script><![endif]-->
- <script src="Changing%20bash%20prompt%20-%20Linux%20Shell%20Scripting%20Tutorial%20-%20A%20Beginner's%20handbook_files/load_002.php"></script></head>
- <body class="mediawiki ltr sitedir-ltr mw-hide-empty-elt ns-0 ns-subject page-Changing_bash_prompt rootpage-Changing_bash_prompt skin-vector action-view"> <div id="mw-page-base" class="noprint"></div>
- <div id="mw-head-base" class="noprint"></div>
- <div id="content" class="mw-body" role="main">
- <a id="top"></a>
- <div class="mw-indicators mw-body-content">
- </div>
- <h1 id="firstHeading" class="firstHeading" lang="en">Changing bash prompt</h1><p>
- <script async="" src="Changing%20bash%20prompt%20-%20Linux%20Shell%20Scripting%20Tutorial%20-%20A%20Beginner's%20handbook_files/adsbygoogle.js" type="text/javascript"></script>
- <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-7825705102693166" data-ad-slot="2740569446" data-ad-format="auto"></ins>
- <script type="text/javascript">
- (adsbygoogle = window.adsbygoogle || []).push({});
- </script>
- </p>
- <div id="bodyContent" class="mw-body-content">
- <div id="siteSub" class="noprint">From Linux Shell Scripting Tutorial - A Beginner's handbook</div> <div id="contentSub"></div>
- <div id="jump-to-nav" class="mw-jump">
- Jump to: <a href="#mw-head">navigation</a>, <a href="#p-search">search</a>
- </div>
- <div id="mw-content-text" dir="ltr" class="mw-content-ltr" lang="en"><div class="mw-parser-output"><span class="noprint" style=""display:"><table id="toc" style="width: 100%; background: #FAF5FF; border-color:#DDCEF2;border-style:solid;border-width:0.077em;padding:0.692em;line-height:1.5em;"><tbody><tr><td style="text-align: left; width:33%"><a href="https://bash.cyberciti.biz/guide/Using_aliases" title="Using aliases">← Using aliases</a></td><td style="text-align: center; width: 33%"><b><a href="https://bash.cyberciti.biz/guide/Main_Page" title="Main Page">Home</a></b></td><td style="text-align: right; width: 33%"><a href="https://bash.cyberciti.biz/guide/Setting_shell_options" title="Setting shell options">Setting shell options →</a></td></tr></tbody></table></span>
- <ul><li>Task: You need to <b>customize your bash prompt</b> by editing PS1 variable.</li>
- <li>Display, your current prompt setting, enter:</li></ul>
- <div class="mw-highlight mw-content-ltr" dir="ltr"><pre><span></span><span class="nb">echo</span> <span class="nv">$PS1</span>
- </pre></div>
- <p>Sample outputs:
- </p>
- <pre>\u@\h:\w\$</pre>
- <ul><li>For testing purpose set PS1 as follows and notice the change:</li></ul>
- <div class="mw-highlight mw-content-ltr" dir="ltr"><pre><span></span><span class="nv">PS1</span><span class="o">=</span><span class="s1">'your wish is my command : '</span>
- </pre></div>
- <p>Sample outputs:
- </p>
- <pre>vivek@vivek-desktop:~$ PS1='your wish is my command : '
- your wish is my command : </pre>
- <div id="toc" class="toc"><div class="toctitle" dir="ltr" lang="en"><h2>Contents</h2><span class="toctoggle"> [<a role="button" tabindex="0" class="togglelink">hide</a>] </span></div>
- <ul>
- <li class="toclevel-1 tocsection-1"><a href="#Customizing_Prompt"><span class="tocnumber">1</span> <span class="toctext">Customizing Prompt</span></a></li>
- <li class="toclevel-1 tocsection-2"><a href="#Adding_color_to_prompt"><span class="tocnumber">2</span> <span class="toctext">Adding color to prompt</span></a></li>
- <li class="toclevel-1 tocsection-3"><a href="#How_do_I_make_prompt_setting_permanent.3F"><span class="tocnumber">3</span> <span class="toctext">How do I make prompt setting permanent?</span></a></li>
- <li class="toclevel-1 tocsection-4"><a href="#PROMPT_COMMAND_variable"><span class="tocnumber">4</span> <span class="toctext">PROMPT_COMMAND variable</span></a>
- <ul>
- <li class="toclevel-2 tocsection-5"><a href="#Creating_complex_prompt"><span class="tocnumber">4.1</span> <span class="toctext">Creating complex prompt</span></a></li>
- </ul>
- </li>
- <li class="toclevel-1 tocsection-6"><a href="#References"><span class="tocnumber">5</span> <span class="toctext">References</span></a></li>
- <li class="toclevel-1 tocsection-7"><a href="#External_links"><span class="tocnumber">6</span> <span class="toctext">External links</span></a></li>
- </ul>
- </div>
- <h2><span class="mw-headline" id="Customizing_Prompt">Customizing Prompt</span></h2>
- <p>Bash shell allows prompt strings to be customized by inserting a
- number of backslash-escaped special characters. Quoting from the bash
- man page:
- </p>
- <table style=""cellpadding="20"" width="100%" cellspacing="0" border="1">
- <tbody><tr>
- <th style="background:#ffdead;">Sequence
- </th>
- <th style="background:#ffdead;">Description
- </th></tr>
- <tr>
- <td>\a
- </td>
- <td>An ASCII bell character (07)
- </td></tr>
- <tr>
- <td>\d
- </td>
- <td>The date in "Weekday Month Date" format (e.g., "Tue May 26")
- </td></tr>
- <tr>
- <td>\e
- </td>
- <td>An ASCII escape character (033)
- </td></tr>
- <tr>
- <td>\h
- </td>
- <td>The hostname up to the first .
- </td></tr>
- <tr>
- <td>\H
- </td>
- <td>The hostname (FQDN)
- </td></tr>
- <tr>
- <td>\j
- </td>
- <td>The number of jobs currently managed by the shell
- </td></tr>
- <tr>
- <td>\l
- </td>
- <td>The basename of the shell’s terminal device name
- </td></tr>
- <tr>
- <td>\n
- </td>
- <td>Newline
- </td></tr>
- <tr>
- <td>\r
- </td>
- <td>Carriage return
- </td></tr>
- <tr>
- <td>\s
- </td>
- <td>The name of the shell, the basename of $0 (the portion following the final slash)
- </td></tr>
- <tr>
- <td>\t
- </td>
- <td>The current time in 24-hour HH:MM:SS format
- </td></tr>
- <tr>
- <td>\T
- </td>
- <td>The current time in 12-hour HH:MM:SS format
- </td></tr>
- <tr>
- <td>\@
- </td>
- <td>The current time in 12-hour am/pm format
- </td></tr>
- <tr>
- <td>\A
- </td>
- <td>The current time in 24-hour HH:MM format
- </td></tr>
- <tr>
- <td>\u
- </td>
- <td>The username of the current user
- </td></tr>
- <tr>
- <td>\v
- </td>
- <td>The version of bash (e.g., 2.00)
- </td></tr>
- <tr>
- <td>\V T
- </td>
- <td>The release of bash, version + patch level (e.g., 2.00.0)
- </td></tr>
- <tr>
- <td>\w
- </td>
- <td>The current working directory, with $HOME abbreviated with a tilde
- </td></tr>
- <tr>
- <td>\W
- </td>
- <td>The basename of the current working directory, with $HOME abbreviated with a tilde
- </td></tr>
- <tr>
- <td>\!
- </td>
- <td>The history number of this command
- </td></tr>
- <tr>
- <td>\#
- </td>
- <td>The command number of this command
- </td></tr>
- <tr>
- <td>\$
- </td>
- <td>If the effective UID is 0, a #, otherwise a $
- </td></tr>
- <tr>
- <td>\nnn
- </td>
- <td>The character corresponding to the octal number nnn
- </td></tr>
- <tr>
- <td>\\
- </td>
- <td>A backslash
- </td></tr>
- <tr>
- <td>\[
- </td>
- <td>Begin a sequence of non-printing characters, which could be used to embed a terminal control sequence into the prompt
- </td></tr>
- <tr>
- <td>\]
- </td>
- <td>End a sequence of non-printing characters
- </td></tr></tbody></table>
- <p>You can use above backslash-escaped sequence to display name of the host with current working directory:
- </p>
- <div class="mw-highlight mw-content-ltr" dir="ltr"><pre><span></span><span class="nv">PS1</span><span class="o">=</span><span class="s1">'\h \W $ '</span>
- </pre></div>
- <h2><span class="mw-headline" id="Adding_color_to_prompt">Adding color to prompt</span></h2>
- <p>It is quite easy to add colors to your prompt. Set green color prompt for normal user account<sup id="cite_ref-1" class="reference"><a href="#cite_note-1">[1]</a></sup>:
- </p>
- <div class="mw-highlight mw-content-ltr" dir="ltr"><pre><span></span><span class="nb">export</span> <span class="nv">PS1</span><span class="o">=</span><span class="s1">'\[\e[1;32m\][\u@\h \W]\$\[\e[0m\] '</span>
- </pre></div>
- <p>And red color prompt for root user account:
- </p>
- <div class="mw-highlight mw-content-ltr" dir="ltr"><pre><span></span><span class="nb">export</span> <span class="nv">PS1</span><span class="o">=</span><span class="s1">'\[\e[1;31m\][\u@\h \W]\$\[\e[0m\] '</span>
- </pre></div>
- <h2><span id="How_do_I_make_prompt_setting_permanent?"></span><span class="mw-headline" id="How_do_I_make_prompt_setting_permanent.3F">How do I make prompt setting permanent?</span></h2>
- <p>Edit your ~/.<a href="https://bash.cyberciti.biz/guide/Bashrc" title="Bashrc">bashrc</a> or ~/.<a href="https://bash.cyberciti.biz/guide/Bash_profile" title="Bash profile">bash_profile</a>
- </p>
- <div class="mw-highlight mw-content-ltr" dir="ltr"><pre><span></span>vi ~/.bashrc
- </pre></div>
- <p>Append your PS1 definition:
- </p>
- <div class="mw-highlight mw-content-ltr" dir="ltr"><pre><span></span><span class="nb">export</span> <span class="nv">PS1</span><span class="o">=</span><span class="s1">'\[\e[1;32m\][\u@\h \W]\$\[\e[0m\] '</span>
- </pre></div>
- <p>Save and close the file.
- </p>
- <h2><span class="mw-headline" id="PROMPT_COMMAND_variable">PROMPT_COMMAND variable</span></h2>
- <p>If PROMPT_COMMAND environment variable set, the value is executed as a
- command prior to issuing each primary prompt. In other words, the
- contents of this variable are executed as a regular Bash command just
- before Bash displays a prompt<sup id="cite_ref-2" class="reference"><a href="#cite_note-2">[2]</a></sup>:
- </p>
- <div class="mw-highlight mw-content-ltr" dir="ltr"><pre><span></span><span class="nv">PROMPT_COMMAND</span><span class="o">=</span><span class="s2">"echo Yahooo"</span>
- </pre></div>
- <p>Sample outputs:
- </p>
- <pre>[vivek@vivek-desktop man]$ PROMPT_COMMAND="echo Yahooo"
- Yahooo
- [vivek@vivek-desktop man]$ date
- Tue Oct 20 23:50:01 IST 2009
- Yahooo
- </pre>
- <h3><span class="mw-headline" id="Creating_complex_prompt">Creating complex prompt</span></h3>
- <p>Edit ~/<a href="https://bash.cyberciti.biz/guide/.bashrc" title=".bashrc">.bashrc</a> file:
- </p>
- <div class="mw-highlight mw-content-ltr" dir="ltr"><pre><span></span>vi ~/.bashrc
- </pre></div>
- <p>Add the following two shell <a href="https://bash.cyberciti.biz/guide/Functions" class="mw-redirect" title="Functions">functions</a><sup id="cite_ref-3" class="reference"><a href="#cite_note-3">[3]</a></sup>
- </p>
- <div class="mw-highlight mw-content-ltr" dir="ltr"><pre><span></span>bash_prompt_command<span class="o">()</span> <span class="o">{</span>
- <span class="c1"># How many characters of the $PWD should be kept</span>
- <span class="nb">local</span> <span class="nv">pwdmaxlen</span><span class="o">=</span><span class="m">25</span>
- <span class="c1"># Indicate that there has been dir truncation</span>
- <span class="nb">local</span> <span class="nv">trunc_symbol</span><span class="o">=</span><span class="s2">".."</span>
- <span class="nb">local</span> <span class="nv">dir</span><span class="o">=</span><span class="si">${</span><span class="nv">PWD</span><span class="p">##*/</span><span class="si">}</span>
- <span class="nv">pwdmaxlen</span><span class="o">=</span><span class="k">$((</span> <span class="o">(</span> pwdmaxlen < <span class="si">${#</span><span class="nv">dir</span><span class="si">}</span> <span class="o">)</span> ? <span class="si">${#</span><span class="nv">dir</span><span class="si">}</span> : pwdmaxlen <span class="k">))</span>
- <span class="nv">NEW_PWD</span><span class="o">=</span><span class="si">${</span><span class="nv">PWD</span><span class="p">/#</span><span class="nv">$HOME</span><span class="p">/</span><span class="se">\~</span><span class="si">}</span>
- <span class="nb">local</span> <span class="nv">pwdoffset</span><span class="o">=</span><span class="k">$((</span> <span class="si">${#</span><span class="nv">NEW_PWD</span><span class="si">}</span> <span class="o">-</span> pwdmaxlen <span class="k">))</span>
- <span class="k">if</span> <span class="o">[</span> <span class="si">${</span><span class="nv">pwdoffset</span><span class="si">}</span> -gt <span class="s2">"0"</span> <span class="o">]</span>
- <span class="k">then</span>
- <span class="nv">NEW_PWD</span><span class="o">=</span><span class="si">${</span><span class="nv">NEW_PWD</span><span class="p">:</span><span class="nv">$pwdoffset</span><span class="p">:</span><span class="nv">$pwdmaxlen</span><span class="si">}</span>
- <span class="nv">NEW_PWD</span><span class="o">=</span><span class="si">${</span><span class="nv">trunc_symbol</span><span class="si">}</span>/<span class="si">${</span><span class="nv">NEW_PWD</span><span class="p">#*/</span><span class="si">}</span>
- <span class="k">fi</span>
- <span class="o">}</span>
- bash_prompt<span class="o">()</span> <span class="o">{</span>
- <span class="k">case</span> <span class="nv">$TERM</span> in
- xterm*<span class="p">|</span>rxvt*<span class="o">)</span>
- <span class="nb">local</span> <span class="nv">TITLEBAR</span><span class="o">=</span><span class="s1">'\[\033]0;\u:${NEW_PWD}\007\]'</span>
- <span class="p">;;</span>
- *<span class="o">)</span>
- <span class="nb">local</span> <span class="nv">TITLEBAR</span><span class="o">=</span><span class="s2">""</span>
- <span class="p">;;</span>
- <span class="k">esac</span>
- <span class="nb">local</span> <span class="nv">NONE</span><span class="o">=</span><span class="s2">"\[\033[0m\]"</span> <span class="c1"># unsets color to term's fg color</span>
- <span class="c1"># regular colors</span>
- <span class="nb">local</span> <span class="nv">K</span><span class="o">=</span><span class="s2">"\[\033[0;30m\]"</span> <span class="c1"># black</span>
- <span class="nb">local</span> <span class="nv">R</span><span class="o">=</span><span class="s2">"\[\033[0;31m\]"</span> <span class="c1"># red</span>
- <span class="nb">local</span> <span class="nv">G</span><span class="o">=</span><span class="s2">"\[\033[0;32m\]"</span> <span class="c1"># green</span>
- <span class="nb">local</span> <span class="nv">Y</span><span class="o">=</span><span class="s2">"\[\033[0;33m\]"</span> <span class="c1"># yellow</span>
- <span class="nb">local</span> <span class="nv">B</span><span class="o">=</span><span class="s2">"\[\033[0;34m\]"</span> <span class="c1"># blue</span>
- <span class="nb">local</span> <span class="nv">M</span><span class="o">=</span><span class="s2">"\[\033[0;35m\]"</span> <span class="c1"># magenta</span>
- <span class="nb">local</span> <span class="nv">C</span><span class="o">=</span><span class="s2">"\[\033[0;36m\]"</span> <span class="c1"># cyan</span>
- <span class="nb">local</span> <span class="nv">W</span><span class="o">=</span><span class="s2">"\[\033[0;37m\]"</span> <span class="c1"># white</span>
- <span class="c1"># emphasized (bolded) colors</span>
- <span class="nb">local</span> <span class="nv">EMK</span><span class="o">=</span><span class="s2">"\[\033[1;30m\]"</span>
- <span class="nb">local</span> <span class="nv">EMR</span><span class="o">=</span><span class="s2">"\[\033[1;31m\]"</span>
- <span class="nb">local</span> <span class="nv">EMG</span><span class="o">=</span><span class="s2">"\[\033[1;32m\]"</span>
- <span class="nb">local</span> <span class="nv">EMY</span><span class="o">=</span><span class="s2">"\[\033[1;33m\]"</span>
- <span class="nb">local</span> <span class="nv">EMB</span><span class="o">=</span><span class="s2">"\[\033[1;34m\]"</span>
- <span class="nb">local</span> <span class="nv">EMM</span><span class="o">=</span><span class="s2">"\[\033[1;35m\]"</span>
- <span class="nb">local</span> <span class="nv">EMC</span><span class="o">=</span><span class="s2">"\[\033[1;36m\]"</span>
- <span class="nb">local</span> <span class="nv">EMW</span><span class="o">=</span><span class="s2">"\[\033[1;37m\]"</span>
- <span class="c1"># background colors</span>
- <span class="nb">local</span> <span class="nv">BGK</span><span class="o">=</span><span class="s2">"\[\033[40m\]"</span>
- <span class="nb">local</span> <span class="nv">BGR</span><span class="o">=</span><span class="s2">"\[\033[41m\]"</span>
- <span class="nb">local</span> <span class="nv">BGG</span><span class="o">=</span><span class="s2">"\[\033[42m\]"</span>
- <span class="nb">local</span> <span class="nv">BGY</span><span class="o">=</span><span class="s2">"\[\033[43m\]"</span>
- <span class="nb">local</span> <span class="nv">BGB</span><span class="o">=</span><span class="s2">"\[\033[44m\]"</span>
- <span class="nb">local</span> <span class="nv">BGM</span><span class="o">=</span><span class="s2">"\[\033[45m\]"</span>
- <span class="nb">local</span> <span class="nv">BGC</span><span class="o">=</span><span class="s2">"\[\033[46m\]"</span>
- <span class="nb">local</span> <span class="nv">BGW</span><span class="o">=</span><span class="s2">"\[\033[47m\]"</span>
- <span class="nb">local</span> <span class="nv">UC</span><span class="o">=</span><span class="nv">$W</span> <span class="c1"># user's color</span>
- <span class="o">[</span> <span class="nv">$UID</span> -eq <span class="s2">"0"</span> <span class="o">]</span> <span class="o">&&</span> <span class="nv">UC</span><span class="o">=</span><span class="nv">$R</span> <span class="c1"># root's color</span>
- <span class="nv">PS1</span><span class="o">=</span><span class="s2">"</span><span class="nv">$TITLEBAR</span><span class="s2"> </span><span class="si">${</span><span class="nv">EMK</span><span class="si">}</span><span class="s2">[</span><span class="si">${</span><span class="nv">UC</span><span class="si">}</span><span class="s2">\u</span><span class="si">${</span><span class="nv">EMK</span><span class="si">}</span><span class="s2">@</span><span class="si">${</span><span class="nv">UC</span><span class="si">}</span><span class="s2">\h </span><span class="si">${</span><span class="nv">EMB</span><span class="si">}</span><span class="s2">\${NEW_PWD}</span><span class="si">${</span><span class="nv">EMK</span><span class="si">}</span><span class="s2">]</span><span class="si">${</span><span class="nv">UC</span><span class="si">}</span><span class="s2">\\</span>$<span class="s2"> </span><span class="si">${</span><span class="nv">NONE</span><span class="si">}</span><span class="s2">"</span>
- <span class="c1"># without colors: PS1="[\u@\h \${NEW_PWD}]\\$ "</span>
- <span class="c1"># extra backslash in front of \$ to make bash colorize the prompt</span>
- <span class="o">}</span>
- <span class="c1"># init it by setting PROMPT_COMMAND</span>
- <span class="nv">PROMPT_COMMAND</span><span class="o">=</span>bash_prompt_command
- bash_prompt
- <span class="nb">unset</span> bash_prompt
- </pre></div>
- <h2><span class="mw-headline" id="References">References</span></h2>
- <div class="mw-references-wrap"><ol class="references">
- <li id="cite_note-1"><span class="mw-cite-backlink"><a href="#cite_ref-1"><span class="cite-accessibility-label">Jump up </span>↑</a></span> <span class="reference-text"><a rel="nofollow" class="external text" href="https://www.cyberciti.biz/faq/bash-shell-change-the-color-of-my-shell-prompt-under-linux-or-unix/">BASH Shell change the color of my shell prompt under Linux or UNIX</a></span>
- </li>
- <li id="cite_note-2"><span class="mw-cite-backlink"><a href="#cite_ref-2"><span class="cite-accessibility-label">Jump up </span>↑</a></span> <span class="reference-text"><a rel="nofollow" class="external text" href="http://tldp.org/HOWTO/Bash-Prompt-HOWTO/x264.html">PROMPT_COMMAND</a> from Bash prompt howto</span>
- </li>
- <li id="cite_note-3"><span class="mw-cite-backlink"><a href="#cite_ref-3"><span class="cite-accessibility-label">Jump up </span>↑</a></span> <span class="reference-text"><a rel="nofollow" class="external text" href="https://wiki.archlinux.org/index.php/Color_Bash_Prompt">Color bash prompt</a> code taken from the official Arch Linux wiki</span>
- </li>
- </ol></div>
- <h2><span class="mw-headline" id="External_links">External links</span></h2>
- <ul><li><a rel="nofollow" class="external text" href="https://www.cyberciti.biz/tips/howto-linux-unix-bash-shell-setup-prompt.html">How to: Change / Setup bash custom prompt (PS1)</a></li>
- <li><a rel="nofollow" class="external text" href="https://www.cyberciti.biz/faq/bash-shell-change-the-color-of-my-shell-prompt-under-linux-or-unix/">BASH Shell change the color of my shell prompt under Linux or UNIX</a></li>
- <li><a rel="nofollow" class="external text" href="https://wiki.archlinux.org/index.php/Color_Bash_Prompt">Color Bash Prompt</a></li>
- <li><a rel="nofollow" class="external text" href="http://tldp.org/HOWTO/Bash-Prompt-HOWTO/">Bash Prompt HOWTO</a></li></ul>
- <span class="noprint" style=""display:"><table id="toc" style="width: 100%; background: #FAF5FF; border-color:#DDCEF2;border-style:solid;border-width:0.077em;padding:0.692em;line-height:1.5em;"><tbody><tr><td style="text-align: left; width:33%"><a href="https://bash.cyberciti.biz/guide/Using_aliases" title="Using aliases">← Using aliases</a></td><td style="text-align: center; width: 33%"><b><a href="https://bash.cyberciti.biz/guide/Main_Page" title="Main Page">Home</a></b></td><td style="text-align: right; width: 33%"><a href="https://bash.cyberciti.biz/guide/Setting_shell_options" title="Setting shell options">Setting shell options →</a></td></tr></tbody></table></span>
- </div>
- </div><p>
- <script async="" src="Changing%20bash%20prompt%20-%20Linux%20Shell%20Scripting%20Tutorial%20-%20A%20Beginner's%20handbook_files/adsbygoogle.js" type="text/javascript"></script>
- <ins class="adsbygoogle" style="display:inline-block;width:336px;height:280px" data-ad-client="ca-pub-7825705102693166" data-ad-slot="5804044661"></ins>
- <script type="text/javascript">
- (adsbygoogle = window.adsbygoogle || []).push({});
- </script>
- </p>
- <div class="printfooter">
- Retrieved from "<a dir="ltr" href="https://bash.cyberciti.biz/wiki/index.php?title=Changing_bash_prompt&oldid=3552">https://bash.cyberciti.biz/wiki/index.php?title=Changing_bash_prompt&oldid=3552</a>" </div>
- <div id="catlinks" class="catlinks" data-mw="interface"><div id="mw-normal-catlinks" class="mw-normal-catlinks"><a href="https://bash.cyberciti.biz/guide/Special:Categories" title="Special:Categories">Categories</a>: <ul><li><a href="https://bash.cyberciti.biz/guide/Category:Variables_and_Quoting" title="Category:Variables and Quoting">Variables and Quoting</a></li><li><a href="https://bash.cyberciti.biz/guide/Category:Commands" title="Category:Commands">Commands</a></li></ul></div></div> <div class="visualClear"></div>
- </div>
- </div>
- <div id="mw-navigation">
- <h2>Navigation menu</h2>
- <div id="mw-head">
- <div id="p-personal" role="navigation" class="" aria-labelledby="p-personal-label">
- <h3 id="p-personal-label">Personal tools</h3>
- <ul>
- <li id="pt-login"><a href="https://bash.cyberciti.biz/wiki/index.php?title=Special:UserLogin&returnto=Changing+bash+prompt" title="You are encouraged to log in; however, it is not mandatory [Alt+Shift+o]" accesskey="o">Log in</a></li> </ul>
- </div>
- <div id="left-navigation">
- <div id="p-namespaces" role="navigation" class="vectorTabs" aria-labelledby="p-namespaces-label">
- <h3 id="p-namespaces-label">Namespaces</h3>
- <ul>
- <li id="ca-nstab-main" class="selected"><span><a href="https://bash.cyberciti.biz/guide/Changing_bash_prompt" title="View the content page [Alt+Shift+c]" accesskey="c">Page</a></span></li><li id="ca-talk" class="new"><span><a href="https://bash.cyberciti.biz/wiki/index.php?title=Talk:Changing_bash_prompt&action=edit&redlink=1" rel="discussion" title="Discussion about the content page (page does not exist) [Alt+Shift+t]" accesskey="t">Discussion</a></span></li> </ul>
- </div>
- <div id="p-variants" role="navigation" class="vectorMenu emptyPortlet" aria-labelledby="p-variants-label">
- <input class="vectorMenuCheckbox" aria-labelledby="p-variants-label" type="checkbox">
- <h3 id="p-variants-label">
- <span>Variants</span>
- </h3>
- <div class="menu">
- <ul>
- </ul>
- </div>
- </div>
- </div>
- <div id="right-navigation">
- <div id="p-views" role="navigation" class="vectorTabs" aria-labelledby="p-views-label">
- <h3 id="p-views-label">Views</h3>
- <ul>
- <li id="ca-view" class="collapsible selected"><span><a href="https://bash.cyberciti.biz/guide/Changing_bash_prompt">Read</a></span></li><li id="ca-viewsource" class="collapsible"><span><a href="https://bash.cyberciti.biz/wiki/index.php?title=Changing_bash_prompt&action=edit" title="This page is protected.
- You can view its source [Alt+Shift+e]" accesskey="e">View source</a></span></li><li id="ca-history" class="collapsible"><span><a href="https://bash.cyberciti.biz/wiki/index.php?title=Changing_bash_prompt&action=history" title="Past revisions of this page [Alt+Shift+h]" accesskey="h">View history</a></span></li> </ul>
- </div>
- <div id="p-cactions" role="navigation" class="vectorMenu emptyPortlet" aria-labelledby="p-cactions-label" style="">
- <input class="vectorMenuCheckbox" aria-labelledby="p-cactions-label" type="checkbox">
- <h3 id="p-cactions-label"><span>More</span></h3>
- <div class="menu">
- <ul>
- </ul>
- </div>
- </div>
- <div id="p-search" role="search">
- <h3>
- <label for="searchInput">Search</label>
- </h3>
- <form action="/wiki/index.php" id="searchform">
- <div id="simpleSearch">
- <input name="search" placeholder="Search Linux Shell Scripting Tutorial - A Beginner's handbook" title="Search Linux Shell Scripting Tutorial - A Beginner's handbook [Alt+Shift+f]" accesskey="f" id="searchInput" tabindex="1" autocomplete="off" type="search"><input value="Special:Search" name="title" type="hidden"><input name="go" value="Go" title="Go to a page with this exact name if it exists" id="searchButton" class="searchButton" type="submit"> </div>
- </form>
- </div>
- </div>
- </div>
- <div id="mw-panel">
- <div id="p-logo" role="banner"><a class="mw-wiki-logo" href="https://bash.cyberciti.biz/guide/Main_Page" title="Visit the main page"></a></div>
- <div class="portal" role="navigation" id="p-navigation" aria-labelledby="p-navigation-label">
- <h3 id="p-navigation-label">Navigation</h3>
- <div class="body">
- <ul>
- <li id="n-mainpage-description"><a href="https://bash.cyberciti.biz/guide/Main_Page" title="Visit the main page [Alt+Shift+z]" accesskey="z">Main page</a></li><li id="n-recentchanges"><a href="https://bash.cyberciti.biz/guide/Special:RecentChanges" title="A list of recent changes in the wiki [Alt+Shift+r]" accesskey="r">Recent changes</a></li><li id="n-randompage"><a href="https://bash.cyberciti.biz/guide/Special:Random" title="Load a random page [Alt+Shift+x]" accesskey="x">Random page</a></li><li id="n-help"><a href="https://www.mediawiki.org/wiki/Special:MyLanguage/Help:Contents" title="The place to find out">Help</a></li> </ul>
- </div>
- </div>
- <div class="portal" role="navigation" id="p-tb" aria-labelledby="p-tb-label">
- <h3 id="p-tb-label">Tools</h3>
- <div class="body">
- <ul>
- <li id="t-whatlinkshere"><a href="https://bash.cyberciti.biz/guide/Special:WhatLinksHere/Changing_bash_prompt" title="A list of all wiki pages that link here [Alt+Shift+j]" accesskey="j">What links here</a></li><li id="t-recentchangeslinked"><a href="https://bash.cyberciti.biz/guide/Special:RecentChangesLinked/Changing_bash_prompt" rel="nofollow" title="Recent changes in pages linked from this page [Alt+Shift+k]" accesskey="k">Related changes</a></li><li id="t-specialpages"><a href="https://bash.cyberciti.biz/guide/Special:SpecialPages" title="A list of all special pages [Alt+Shift+q]" accesskey="q">Special pages</a></li><li id="t-print"><a href="https://bash.cyberciti.biz/wiki/index.php?title=Changing_bash_prompt&printable=yes" rel="alternate" title="Printable version of this page [Alt+Shift+p]" accesskey="p">Printable version</a></li><li id="t-permalink"><a href="https://bash.cyberciti.biz/wiki/index.php?title=Changing_bash_prompt&oldid=3552" title="Permanent link to this revision of the page">Permanent link</a></li><li id="t-info"><a href="https://bash.cyberciti.biz/wiki/index.php?title=Changing_bash_prompt&action=info" title="More information about this page">Page information</a></li> </ul>
- </div>
- </div>
- <center><p><script async="" src="Changing%20bash%20prompt%20-%20Linux%20Shell%20Scripting%20Tutorial%20-%20A%20Beginner's%20handbook_files/adsbygoogle.js" type="text/javascript"></script>
- <ins class="adsbygoogle" style="display:inline-block;width:120px;height:600px; " data-ad-client="ca-pub-7825705102693166" data-ad-slot="8378479061"></ins>
- <script type="text/javascript">
- (adsbygoogle = window.adsbygoogle || []).push({});
- </script></p></center>
- </div>
- </div>
- <div id="footer" role="contentinfo">
- <ul id="footer-info">
- <li id="footer-info-lastmod"> This page was last edited on 17 July 2017, at 15:27.</li>
- <li id="footer-info-copyright">Content is available under <a class="external" rel="nofollow" href="https://creativecommons.org/licenses/by-nc-sa/3.0/">Attribution-Noncommercial-Share Alike 3.0 Unported</a> unless otherwise noted.</li>
- </ul>
- <ul id="footer-places">
- <li id="footer-places-privacy"><a href="https://bash.cyberciti.biz/guide/Linux_Shell_Scripting_Tutorial_-_A_Beginner%27s_handbook:Privacy_policy" title="Linux Shell Scripting Tutorial - A Beginner's handbook:Privacy policy">Privacy policy</a></li>
- <li id="footer-places-about"><a href="https://bash.cyberciti.biz/guide/Linux_Shell_Scripting_Tutorial_-_A_Beginner%27s_handbook:About" title="Linux Shell Scripting Tutorial - A Beginner's handbook:About">About Linux Shell Scripting Tutorial - A Beginner's handbook</a></li>
- <li id="footer-places-disclaimer"><a href="https://bash.cyberciti.biz/guide/Linux_Shell_Scripting_Tutorial_-_A_Beginner%27s_handbook:General_disclaimer" title="Linux Shell Scripting Tutorial - A Beginner's handbook:General disclaimer">Disclaimers</a></li>
- <li id="footer-places-mobileview"><a href="https://bash.cyberciti.biz/wiki/index.php?title=Changing_bash_prompt&mobileaction=toggle_view_mobile" class="noprint stopMobileRedirectToggle">Mobile view</a></li>
- </ul>
- <ul id="footer-icons" class="noprint">
- <li id="footer-copyrightico">
- <a href="https://creativecommons.org/licenses/by-nc-sa/3.0/"><img src="Changing%20bash%20prompt%20-%20Linux%20Shell%20Scripting%20Tutorial%20-%20A%20Beginner's%20handbook_files/88x31.png" alt="Attribution-Noncommercial-Share Alike 3.0 Unported" width="88" height="31"></a> </li>
- <li id="footer-poweredbyico">
- <a href="https://www.mediawiki.org/"><img src="Changing%20bash%20prompt%20-%20Linux%20Shell%20Scripting%20Tutorial%20-%20A%20Beginner's%20handbook_files/poweredby_mediawiki_88x31.png" alt="Powered by MediaWiki" srcset="/wiki/resources/assets/poweredby_mediawiki_132x47.png 1.5x, /wiki/resources/assets/poweredby_mediawiki_176x62.png 2x" width="88" height="31"></a> </li>
- </ul>
- <div style="clear: both;"></div>
- </div>
- <script type="text/javascript">(window.RLQ=window.RLQ||[]).push(function(){mw.config.set({"wgPageParseReport":{"limitreport":{"cputime":"0.038","walltime":"0.040","ppvisitednodes":{"value":231,"limit":1000000},"ppgeneratednodes":{"value":561,"limit":1000000},"postexpandincludesize":{"value":1086,"limit":2097152},"templateargumentsize":{"value":136,"limit":2097152},"expansiondepth":{"value":3,"limit":40},"expensivefunctioncount":{"value":0,"limit":100},"unstrip-depth":{"value":0,"limit":20},"unstrip-size":{"value":12333,"limit":5000000},"timingprofile":["100.00% 11.965 1 -total"," 20.44% 2.446 2 Template:Navigation"]},"cachereport":{"timestamp":"20180818082630","ttl":86400,"transientcontent":false}}});});</script><script type="text/javascript">
- (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
- (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
- m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
- })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
- ga('create', 'UA-108650-10', 'auto');
- ga('set', 'anonymizeIp', true);
- ga('send', 'pageview');
- </script>
- <script type="text/javascript">(window.RLQ=window.RLQ||[]).push(function(){mw.config.set({"wgBackendResponseTime":35});});</script>
- <div style="display: none; font-size: 13px;" class="suggestions"><div class="suggestions-results"></div><div class="suggestions-special"></div></div></body></html>
Add Comment
Please, Sign In to add comment