v1ral_ITS

Bash_PS1.html

Feb 5th, 2026
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 36.90 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html class="client-js" dir="ltr" lang="en"><head>
  3. <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  4. <meta charset="UTF-8">
  5. <title>Changing bash prompt - Linux Shell Scripting Tutorial - A Beginner's handbook</title>
  6. <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>
  7. <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":"+\\"});
  8. });mw.loader.load(["ext.cite.a11y","mediawiki.page.startup","mediawiki.user","mediawiki.hidpi","mediawiki.page.ready","mediawiki.toc","mediawiki.searchSuggest","skins.vector.js"]);});</script>
  9. <link rel="stylesheet" href="Changing%20bash%20prompt%20-%20Linux%20Shell%20Scripting%20Tutorial%20-%20A%20Beginner's%20handbook_files/load.css">
  10. <script async="" src="Changing%20bash%20prompt%20-%20Linux%20Shell%20Scripting%20Tutorial%20-%20A%20Beginner's%20handbook_files/load.php" type="text/javascript"></script>
  11. <style>
  12. .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}
  13. .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}
  14. @media screen {
  15.     .tochidden,.toctoggle{-moz-user-select:none;-webkit-user-select:none;-ms-user-select:none;user-select:none}.toctoggle{font-size:94%}}
  16. @media print {
  17.     .toc.tochidden,.toctoggle{display:none}}</style><style>
  18. .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="">
  19. <link rel="stylesheet" href="Changing%20bash%20prompt%20-%20Linux%20Shell%20Scripting%20Tutorial%20-%20A%20Beginner's%20handbook_files/load_002.css">
  20. <meta name="generator" content="MediaWiki 1.31.0">
  21. <link rel="shortcut icon" href="https://bash.cyberciti.biz/favicon.ico">
  22. <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)">
  23. <link rel="EditURI" type="application/rsd+xml" href="https://bash.cyberciti.biz/wiki/api.php?action=rsd">
  24. <link rel="license" href="https://creativecommons.org/licenses/by-nc-sa/3.0/">
  25. <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&amp;feed=atom">
  26. <!--[if lt IE 9]><script src="/wiki/load.php?debug=false&amp;lang=en&amp;modules=html5shiv&amp;only=scripts&amp;skin=vector&amp;sync=1"></script><![endif]-->
  27. <script src="Changing%20bash%20prompt%20-%20Linux%20Shell%20Scripting%20Tutorial%20-%20A%20Beginner's%20handbook_files/load_002.php"></script></head>
  28. <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>
  29. <div id="mw-head-base" class="noprint"></div>
  30. <div id="content" class="mw-body" role="main">
  31. <a id="top"></a>
  32. <div class="mw-indicators mw-body-content">
  33. </div>
  34. <h1 id="firstHeading" class="firstHeading" lang="en">Changing bash prompt</h1><p>
  35. <script async="" src="Changing%20bash%20prompt%20-%20Linux%20Shell%20Scripting%20Tutorial%20-%20A%20Beginner's%20handbook_files/adsbygoogle.js" type="text/javascript"></script>
  36.  
  37. <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-7825705102693166" data-ad-slot="2740569446" data-ad-format="auto"></ins>
  38. <script type="text/javascript">
  39. (adsbygoogle = window.adsbygoogle || []).push({});
  40. </script>
  41. </p>
  42. <div id="bodyContent" class="mw-body-content">
  43. <div id="siteSub" class="noprint">From Linux Shell Scripting Tutorial - A Beginner's handbook</div> <div id="contentSub"></div>
  44. <div id="jump-to-nav" class="mw-jump">
  45. Jump to: <a href="#mw-head">navigation</a>, <a href="#p-search">search</a>
  46. </div>
  47. <div id="mw-content-text" dir="ltr" class="mw-content-ltr" lang="en"><div class="mw-parser-output"><span class="noprint" style="&quot;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>
  48. <ul><li>Task: You need to <b>customize your bash prompt</b> by editing PS1 variable.</li>
  49. <li>Display, your current prompt setting, enter:</li></ul>
  50. <div class="mw-highlight mw-content-ltr" dir="ltr"><pre><span></span><span class="nb">echo</span> <span class="nv">$PS1</span>
  51. </pre></div>
  52. <p>Sample outputs:
  53. </p>
  54. <pre>\u@\h:\w\$</pre>
  55. <ul><li>For testing purpose set PS1 as follows and notice the change:</li></ul>
  56. <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>
  57. </pre></div>
  58. <p>Sample outputs:
  59. </p>
  60. <pre>vivek@vivek-desktop:~$ PS1='your wish is my command&nbsp;: '
  61. your wish is my command&nbsp;: </pre>
  62. <div id="toc" class="toc"><div class="toctitle" dir="ltr" lang="en"><h2>Contents</h2><span class="toctoggle">&nbsp;[<a role="button" tabindex="0" class="togglelink">hide</a>]&nbsp;</span></div>
  63. <ul>
  64. <li class="toclevel-1 tocsection-1"><a href="#Customizing_Prompt"><span class="tocnumber">1</span> <span class="toctext">Customizing Prompt</span></a></li>
  65. <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>
  66. <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>
  67. <li class="toclevel-1 tocsection-4"><a href="#PROMPT_COMMAND_variable"><span class="tocnumber">4</span> <span class="toctext">PROMPT_COMMAND variable</span></a>
  68. <ul>
  69. <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>
  70. </ul>
  71. </li>
  72. <li class="toclevel-1 tocsection-6"><a href="#References"><span class="tocnumber">5</span> <span class="toctext">References</span></a></li>
  73. <li class="toclevel-1 tocsection-7"><a href="#External_links"><span class="tocnumber">6</span> <span class="toctext">External links</span></a></li>
  74. </ul>
  75. </div>
  76. <h2><span class="mw-headline" id="Customizing_Prompt">Customizing Prompt</span></h2>
  77. <p>Bash shell allows prompt strings to be customized by inserting a
  78. number of backslash-escaped special characters. Quoting from the bash
  79. man page:
  80. </p>
  81. <table style="&quot;cellpadding=&quot;20&quot;" width="100%" cellspacing="0" border="1">
  82. <tbody><tr>
  83. <th style="background:#ffdead;">Sequence
  84. </th>
  85. <th style="background:#ffdead;">Description
  86. </th></tr>
  87. <tr>
  88. <td>\a
  89. </td>
  90. <td>An ASCII bell character (07)
  91. </td></tr>
  92. <tr>
  93. <td>\d
  94. </td>
  95. <td>The date in "Weekday Month Date" format (e.g., "Tue May 26")
  96. </td></tr>
  97. <tr>
  98. <td>\e
  99. </td>
  100. <td>An ASCII escape character (033)
  101. </td></tr>
  102. <tr>
  103. <td>\h
  104. </td>
  105. <td>The hostname up to the first .
  106. </td></tr>
  107. <tr>
  108. <td>\H
  109. </td>
  110. <td>The hostname (FQDN)
  111. </td></tr>
  112. <tr>
  113. <td>\j
  114. </td>
  115. <td>The number of jobs currently managed by the shell
  116. </td></tr>
  117. <tr>
  118. <td>\l
  119. </td>
  120. <td>The basename of the shell’s terminal device name
  121. </td></tr>
  122. <tr>
  123. <td>\n
  124. </td>
  125. <td>Newline
  126. </td></tr>
  127. <tr>
  128. <td>\r
  129. </td>
  130. <td>Carriage return
  131. </td></tr>
  132. <tr>
  133. <td>\s
  134. </td>
  135. <td>The name of the shell, the basename of $0 (the portion following the final slash)
  136. </td></tr>
  137. <tr>
  138. <td>\t
  139. </td>
  140. <td>The current time in 24-hour HH:MM:SS format
  141. </td></tr>
  142. <tr>
  143. <td>\T
  144. </td>
  145. <td>The current time in 12-hour HH:MM:SS format
  146. </td></tr>
  147. <tr>
  148. <td>\@
  149. </td>
  150. <td>The current time in 12-hour am/pm format
  151. </td></tr>
  152. <tr>
  153. <td>\A
  154. </td>
  155. <td>The current time in 24-hour HH:MM format
  156. </td></tr>
  157. <tr>
  158. <td>\u
  159. </td>
  160. <td>The username of the current user
  161. </td></tr>
  162. <tr>
  163. <td>\v
  164. </td>
  165. <td>The version of bash (e.g., 2.00)
  166. </td></tr>
  167. <tr>
  168. <td>\V T
  169. </td>
  170. <td>The release of bash, version + patch level (e.g., 2.00.0)
  171. </td></tr>
  172. <tr>
  173. <td>\w
  174. </td>
  175. <td>The current working directory, with $HOME abbreviated with a tilde
  176. </td></tr>
  177. <tr>
  178. <td>\W
  179. </td>
  180. <td>The basename of the current working directory, with $HOME abbreviated with a tilde
  181. </td></tr>
  182. <tr>
  183. <td>\!
  184. </td>
  185. <td>The history number of this command
  186. </td></tr>
  187. <tr>
  188. <td>\#
  189. </td>
  190. <td>The command number of this command
  191. </td></tr>
  192. <tr>
  193. <td>\$
  194. </td>
  195. <td>If the effective UID is 0, a #, otherwise a $
  196. </td></tr>
  197. <tr>
  198. <td>\nnn
  199. </td>
  200. <td>The character corresponding to the octal number nnn
  201. </td></tr>
  202. <tr>
  203. <td>\\
  204. </td>
  205. <td>A backslash
  206. </td></tr>
  207. <tr>
  208. <td>\[
  209. </td>
  210. <td>Begin a sequence of non-printing characters, which could be used to embed a terminal control sequence into the prompt
  211. </td></tr>
  212. <tr>
  213. <td>\]
  214. </td>
  215. <td>End a sequence of non-printing characters
  216. </td></tr></tbody></table>
  217. <p>You can use above backslash-escaped sequence to display name of the host with current working directory:
  218. </p>
  219. <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>
  220. </pre></div>
  221. <h2><span class="mw-headline" id="Adding_color_to_prompt">Adding color to prompt</span></h2>
  222. <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>:
  223. </p>
  224. <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>
  225. </pre></div>
  226. <p>And red color prompt for root user account:
  227. </p>
  228. <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>
  229. </pre></div>
  230. <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>
  231. <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>
  232. </p>
  233. <div class="mw-highlight mw-content-ltr" dir="ltr"><pre><span></span>vi ~/.bashrc
  234. </pre></div>
  235. <p>Append your PS1 definition:
  236. </p>
  237. <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>
  238. </pre></div>
  239. <p>Save and close the file.
  240. </p>
  241. <h2><span class="mw-headline" id="PROMPT_COMMAND_variable">PROMPT_COMMAND variable</span></h2>
  242. <p>If PROMPT_COMMAND environment variable set, the value is executed as a
  243.  command prior to issuing each primary prompt. In other words, the
  244. contents of this variable are executed as a regular Bash command just
  245. before Bash displays a prompt<sup id="cite_ref-2" class="reference"><a href="#cite_note-2">[2]</a></sup>:
  246. </p>
  247. <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>
  248. </pre></div>
  249. <p>Sample outputs:
  250. </p>
  251. <pre>[vivek@vivek-desktop man]$ PROMPT_COMMAND="echo Yahooo"
  252. Yahooo
  253. [vivek@vivek-desktop man]$ date
  254. Tue Oct 20 23:50:01 IST 2009
  255. Yahooo
  256. </pre>
  257. <h3><span class="mw-headline" id="Creating_complex_prompt">Creating complex prompt</span></h3>
  258. <p>Edit ~/<a href="https://bash.cyberciti.biz/guide/.bashrc" title=".bashrc">.bashrc</a> file:
  259. </p>
  260. <div class="mw-highlight mw-content-ltr" dir="ltr"><pre><span></span>vi ~/.bashrc
  261. </pre></div>
  262. <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>
  263. </p>
  264. <div class="mw-highlight mw-content-ltr" dir="ltr"><pre><span></span>bash_prompt_command<span class="o">()</span> <span class="o">{</span>
  265.     <span class="c1"># How many characters of the $PWD should be kept</span>
  266.     <span class="nb">local</span> <span class="nv">pwdmaxlen</span><span class="o">=</span><span class="m">25</span>
  267.     <span class="c1"># Indicate that there has been dir truncation</span>
  268.     <span class="nb">local</span> <span class="nv">trunc_symbol</span><span class="o">=</span><span class="s2">".."</span>
  269.     <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>
  270.     <span class="nv">pwdmaxlen</span><span class="o">=</span><span class="k">$((</span> <span class="o">(</span> pwdmaxlen &lt; <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>
  271.     <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>
  272.     <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>
  273.     <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>
  274.     <span class="k">then</span>
  275.         <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>
  276.         <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>
  277.     <span class="k">fi</span>
  278. <span class="o">}</span>
  279.  
  280. bash_prompt<span class="o">()</span> <span class="o">{</span>
  281.     <span class="k">case</span> <span class="nv">$TERM</span> in
  282.      xterm*<span class="p">|</span>rxvt*<span class="o">)</span>
  283.          <span class="nb">local</span> <span class="nv">TITLEBAR</span><span class="o">=</span><span class="s1">'\[\033]0;\u:${NEW_PWD}\007\]'</span>
  284.           <span class="p">;;</span>
  285.      *<span class="o">)</span>
  286.          <span class="nb">local</span> <span class="nv">TITLEBAR</span><span class="o">=</span><span class="s2">""</span>
  287.           <span class="p">;;</span>
  288.     <span class="k">esac</span>
  289.     <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>
  290.    
  291.     <span class="c1"># regular colors</span>
  292.     <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>
  293.     <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>
  294.     <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>
  295.     <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>
  296.     <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>
  297.     <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>
  298.     <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>
  299.     <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>
  300.    
  301.     <span class="c1"># emphasized (bolded) colors</span>
  302.     <span class="nb">local</span> <span class="nv">EMK</span><span class="o">=</span><span class="s2">"\[\033[1;30m\]"</span>
  303.     <span class="nb">local</span> <span class="nv">EMR</span><span class="o">=</span><span class="s2">"\[\033[1;31m\]"</span>
  304.     <span class="nb">local</span> <span class="nv">EMG</span><span class="o">=</span><span class="s2">"\[\033[1;32m\]"</span>
  305.     <span class="nb">local</span> <span class="nv">EMY</span><span class="o">=</span><span class="s2">"\[\033[1;33m\]"</span>
  306.     <span class="nb">local</span> <span class="nv">EMB</span><span class="o">=</span><span class="s2">"\[\033[1;34m\]"</span>
  307.     <span class="nb">local</span> <span class="nv">EMM</span><span class="o">=</span><span class="s2">"\[\033[1;35m\]"</span>
  308.     <span class="nb">local</span> <span class="nv">EMC</span><span class="o">=</span><span class="s2">"\[\033[1;36m\]"</span>
  309.     <span class="nb">local</span> <span class="nv">EMW</span><span class="o">=</span><span class="s2">"\[\033[1;37m\]"</span>
  310.    
  311.     <span class="c1"># background colors</span>
  312.     <span class="nb">local</span> <span class="nv">BGK</span><span class="o">=</span><span class="s2">"\[\033[40m\]"</span>
  313.     <span class="nb">local</span> <span class="nv">BGR</span><span class="o">=</span><span class="s2">"\[\033[41m\]"</span>
  314.     <span class="nb">local</span> <span class="nv">BGG</span><span class="o">=</span><span class="s2">"\[\033[42m\]"</span>
  315.     <span class="nb">local</span> <span class="nv">BGY</span><span class="o">=</span><span class="s2">"\[\033[43m\]"</span>
  316.     <span class="nb">local</span> <span class="nv">BGB</span><span class="o">=</span><span class="s2">"\[\033[44m\]"</span>
  317.     <span class="nb">local</span> <span class="nv">BGM</span><span class="o">=</span><span class="s2">"\[\033[45m\]"</span>
  318.     <span class="nb">local</span> <span class="nv">BGC</span><span class="o">=</span><span class="s2">"\[\033[46m\]"</span>
  319.     <span class="nb">local</span> <span class="nv">BGW</span><span class="o">=</span><span class="s2">"\[\033[47m\]"</span>
  320.    
  321.     <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>
  322.     <span class="o">[</span> <span class="nv">$UID</span> -eq <span class="s2">"0"</span> <span class="o">]</span> <span class="o">&amp;&amp;</span> <span class="nv">UC</span><span class="o">=</span><span class="nv">$R</span>   <span class="c1"># root's color</span>
  323.    
  324.     <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>
  325.     <span class="c1"># without colors: PS1="[\u@\h \${NEW_PWD}]\\$ "</span>
  326.     <span class="c1"># extra backslash in front of \$ to make bash colorize the prompt</span>
  327. <span class="o">}</span>
  328. <span class="c1"># init it by setting PROMPT_COMMAND</span>
  329. <span class="nv">PROMPT_COMMAND</span><span class="o">=</span>bash_prompt_command
  330. bash_prompt
  331. <span class="nb">unset</span> bash_prompt
  332. </pre></div>
  333. <h2><span class="mw-headline" id="References">References</span></h2>
  334. <div class="mw-references-wrap"><ol class="references">
  335. <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>
  336. </li>
  337. <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>
  338. </li>
  339. <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>
  340. </li>
  341. </ol></div>
  342. <h2><span class="mw-headline" id="External_links">External links</span></h2>
  343. <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>
  344. <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>
  345. <li><a rel="nofollow" class="external text" href="https://wiki.archlinux.org/index.php/Color_Bash_Prompt">Color Bash Prompt</a></li>
  346. <li><a rel="nofollow" class="external text" href="http://tldp.org/HOWTO/Bash-Prompt-HOWTO/">Bash Prompt HOWTO</a></li></ul>
  347. <span class="noprint" style="&quot;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>
  348.  
  349.  
  350. </div>
  351.  
  352. </div><p>
  353. <script async="" src="Changing%20bash%20prompt%20-%20Linux%20Shell%20Scripting%20Tutorial%20-%20A%20Beginner's%20handbook_files/adsbygoogle.js" type="text/javascript"></script>
  354.  
  355. <ins class="adsbygoogle" style="display:inline-block;width:336px;height:280px" data-ad-client="ca-pub-7825705102693166" data-ad-slot="5804044661"></ins>
  356. <script type="text/javascript">
  357. (adsbygoogle = window.adsbygoogle || []).push({});
  358. </script>
  359. </p>
  360. <div class="printfooter">
  361. Retrieved from "<a dir="ltr" href="https://bash.cyberciti.biz/wiki/index.php?title=Changing_bash_prompt&amp;oldid=3552">https://bash.cyberciti.biz/wiki/index.php?title=Changing_bash_prompt&amp;oldid=3552</a>" </div>
  362. <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>
  363. </div>
  364. </div>
  365. <div id="mw-navigation">
  366. <h2>Navigation menu</h2>
  367. <div id="mw-head">
  368. <div id="p-personal" role="navigation" class="" aria-labelledby="p-personal-label">
  369. <h3 id="p-personal-label">Personal tools</h3>
  370. <ul>
  371. <li id="pt-login"><a href="https://bash.cyberciti.biz/wiki/index.php?title=Special:UserLogin&amp;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>
  372. </div>
  373. <div id="left-navigation">
  374. <div id="p-namespaces" role="navigation" class="vectorTabs" aria-labelledby="p-namespaces-label">
  375. <h3 id="p-namespaces-label">Namespaces</h3>
  376. <ul>
  377. <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&amp;action=edit&amp;redlink=1" rel="discussion" title="Discussion about the content page (page does not exist) [Alt+Shift+t]" accesskey="t">Discussion</a></span></li> </ul>
  378. </div>
  379. <div id="p-variants" role="navigation" class="vectorMenu emptyPortlet" aria-labelledby="p-variants-label">
  380. <input class="vectorMenuCheckbox" aria-labelledby="p-variants-label" type="checkbox">
  381. <h3 id="p-variants-label">
  382. <span>Variants</span>
  383. </h3>
  384. <div class="menu">
  385. <ul>
  386. </ul>
  387. </div>
  388. </div>
  389. </div>
  390. <div id="right-navigation">
  391. <div id="p-views" role="navigation" class="vectorTabs" aria-labelledby="p-views-label">
  392. <h3 id="p-views-label">Views</h3>
  393. <ul>
  394. <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&amp;action=edit" title="This page is protected.
  395. 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&amp;action=history" title="Past revisions of this page [Alt+Shift+h]" accesskey="h">View history</a></span></li> </ul>
  396. </div>
  397. <div id="p-cactions" role="navigation" class="vectorMenu emptyPortlet" aria-labelledby="p-cactions-label" style="">
  398. <input class="vectorMenuCheckbox" aria-labelledby="p-cactions-label" type="checkbox">
  399. <h3 id="p-cactions-label"><span>More</span></h3>
  400. <div class="menu">
  401. <ul>
  402. </ul>
  403. </div>
  404. </div>
  405. <div id="p-search" role="search">
  406. <h3>
  407. <label for="searchInput">Search</label>
  408. </h3>
  409. <form action="/wiki/index.php" id="searchform">
  410. <div id="simpleSearch">
  411. <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>
  412. </form>
  413. </div>
  414. </div>
  415. </div>
  416. <div id="mw-panel">
  417. <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>
  418. <div class="portal" role="navigation" id="p-navigation" aria-labelledby="p-navigation-label">
  419. <h3 id="p-navigation-label">Navigation</h3>
  420. <div class="body">
  421. <ul>
  422. <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>
  423. </div>
  424. </div>
  425. <div class="portal" role="navigation" id="p-tb" aria-labelledby="p-tb-label">
  426. <h3 id="p-tb-label">Tools</h3>
  427. <div class="body">
  428. <ul>
  429. <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&amp;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&amp;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&amp;action=info" title="More information about this page">Page information</a></li> </ul>
  430. </div>
  431. </div>
  432. <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>
  433.  
  434. <ins class="adsbygoogle" style="display:inline-block;width:120px;height:600px; " data-ad-client="ca-pub-7825705102693166" data-ad-slot="8378479061"></ins>
  435. <script type="text/javascript">
  436. (adsbygoogle = window.adsbygoogle || []).push({});
  437. </script></p></center>
  438. </div>
  439. </div>
  440. <div id="footer" role="contentinfo">
  441. <ul id="footer-info">
  442. <li id="footer-info-lastmod"> This page was last edited on 17 July 2017, at 15:27.</li>
  443. <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>
  444. </ul>
  445. <ul id="footer-places">
  446. <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>
  447. <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>
  448. <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>
  449. <li id="footer-places-mobileview"><a href="https://bash.cyberciti.biz/wiki/index.php?title=Changing_bash_prompt&amp;mobileaction=toggle_view_mobile" class="noprint stopMobileRedirectToggle">Mobile view</a></li>
  450. </ul>
  451. <ul id="footer-icons" class="noprint">
  452. <li id="footer-copyrightico">
  453. <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>
  454. <li id="footer-poweredbyico">
  455. <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>
  456. </ul>
  457. <div style="clear: both;"></div>
  458. </div>
  459. <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">
  460.  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  461.  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  462.  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  463.  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
  464.  
  465.  ga('create', 'UA-108650-10', 'auto');
  466.  ga('set', 'anonymizeIp', true);
  467.  ga('send', 'pageview');
  468.  
  469. </script>
  470. <script type="text/javascript">(window.RLQ=window.RLQ||[]).push(function(){mw.config.set({"wgBackendResponseTime":35});});</script>
  471.  
  472.  
  473. <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