<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>WiredRevolution.com &#187; environment variable</title>
	<atom:link href="http://www.wiredrevolution.com/tag/environment-variable/feed" rel="self" type="application/rss+xml" />
	<link>http://www.wiredrevolution.com</link>
	<description>A Bit of Linux Wisdom</description>
	<lastBuildDate>Wed, 18 Jan 2012 22:45:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Find the PID of the current Bash script</title>
		<link>http://www.wiredrevolution.com/bash-programming/find-the-pid-of-the-current-bash-script?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=find-the-pid-of-the-current-bash-script</link>
		<comments>http://www.wiredrevolution.com/bash-programming/find-the-pid-of-the-current-bash-script#comments</comments>
		<pubDate>Sun, 09 Jan 2011 17:18:51 +0000</pubDate>
		<dc:creator>Ryan</dc:creator>
				<category><![CDATA[bash]]></category>
		<category><![CDATA[$$]]></category>
		<category><![CDATA[access]]></category>
		<category><![CDATA[current]]></category>
		<category><![CDATA[environment variable]]></category>
		<category><![CDATA[find]]></category>
		<category><![CDATA[PID]]></category>
		<category><![CDATA[print]]></category>
		<category><![CDATA[process ID]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[variable]]></category>

		<guid isPermaLink="false">http://www.wiredrevolution.com/?p=1438</guid>
		<description><![CDATA[<img src="http://www.wiredrevolution.com/wp-content/uploads/bash_icon.png" width="80" height="34" alt="" title="bash" /><br/>In many cases you will need to determine the PID of a current Bash script or shell. Bash stores a specific variable that allows you to view the process ID of the current shell &#8220;$$&#8216;. You can echo the $$ to print the current PID. $ echo $$23490 Related postsFind the parent PID of a [...]


Related posts<ol><li><a href='http://www.wiredrevolution.com/bash-programming/find-the-parent-pid-of-a-bash-script' rel='bookmark' title='Permanent Link: Find the parent PID of a Bash Script'>Find the parent PID of a Bash Script</a></li>
<li><a href='http://www.wiredrevolution.com/bash-programming/find-the-pid-of-a-background-child-process-in-bash' rel='bookmark' title='Permanent Link: Find the PID of a background child process in Bash'>Find the PID of a background child process in Bash</a></li>
<li><a href='http://www.wiredrevolution.com/bash-programming/find-the-exit-status-of-a-previous-command-in-bash' rel='bookmark' title='Permanent Link: Find the exit status of a previous command in Bash'>Find the exit status of a previous command in Bash</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<img src="http://www.wiredrevolution.com/wp-content/uploads/bash_icon.png" width="80" height="34" alt="" title="bash" /><br/><p>In many cases you will need to determine the PID of a current Bash script or shell. Bash stores a specific variable that allows you to view the process ID of the current shell &#8220;<strong>$$</strong>&#8216;.</p>
<p>You can echo the $$ to print the current PID.<br />
<code>$ echo $$</code><code>23490</code></p>


<p>Related posts<ol><li><a href='http://www.wiredrevolution.com/bash-programming/find-the-parent-pid-of-a-bash-script' rel='bookmark' title='Permanent Link: Find the parent PID of a Bash Script'>Find the parent PID of a Bash Script</a></li>
<li><a href='http://www.wiredrevolution.com/bash-programming/find-the-pid-of-a-background-child-process-in-bash' rel='bookmark' title='Permanent Link: Find the PID of a background child process in Bash'>Find the PID of a background child process in Bash</a></li>
<li><a href='http://www.wiredrevolution.com/bash-programming/find-the-exit-status-of-a-previous-command-in-bash' rel='bookmark' title='Permanent Link: Find the exit status of a previous command in Bash'>Find the exit status of a previous command in Bash</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.wiredrevolution.com/bash-programming/find-the-pid-of-the-current-bash-script/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>View process environment details with proc</title>
		<link>http://www.wiredrevolution.com/system-administration/view-process-environment-details-with-proc?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=view-process-environment-details-with-proc</link>
		<comments>http://www.wiredrevolution.com/system-administration/view-process-environment-details-with-proc#comments</comments>
		<pubDate>Wed, 10 Dec 2008 12:42:25 +0000</pubDate>
		<dc:creator>Ryan</dc:creator>
				<category><![CDATA[system administration]]></category>
		<category><![CDATA[environ]]></category>
		<category><![CDATA[environment variable]]></category>
		<category><![CDATA[PID]]></category>
		<category><![CDATA[proc]]></category>
		<category><![CDATA[tr]]></category>

		<guid isPermaLink="false">http://www.wiredrevolution.com/?p=848</guid>
		<description><![CDATA[<img src="http://www.wiredrevolution.com/wp-content/uploads/sysadmin_icon.png" width="80" height="94" alt="" title="system administration" /><br/>The process environment consists of all the individual environment variables which are passed on to the program by the shell when the program is launched. This environment can be read and changed by the program during its execution, and can affect how a program is linked or how it executes. For all these reasons it [...]


Related posts<ol><li><a href='http://www.wiredrevolution.com/system-administration/view-system-information-with-proccpuinfo-and-procmeminfo' rel='bookmark' title='Permanent Link: View system information with /proc/cpuinfo and /proc/meminfo'>View system information with /proc/cpuinfo and /proc/meminfo</a></li>
<li><a href='http://www.wiredrevolution.com/bash-programming/find-the-pid-of-a-background-child-process-in-bash' rel='bookmark' title='Permanent Link: Find the PID of a background child process in Bash'>Find the PID of a background child process in Bash</a></li>
<li><a href='http://www.wiredrevolution.com/system-administration/how-to-release-the-linux-disk-cache' rel='bookmark' title='Permanent Link: How to release the Linux disk cache'>How to release the Linux disk cache</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<img src="http://www.wiredrevolution.com/wp-content/uploads/sysadmin_icon.png" width="80" height="94" alt="" title="system administration" /><br/><p>The <strong>process environment</strong> consists of all the individual <strong>environment variables</strong> which are passed on to the program by the shell when the program is launched. This environment can be read and changed by the program during its execution, and can affect how a program is linked or how it executes. For all these reasons it may be important at times to see exactly what the environment contains. The <strong>proc</strong> filesystem provides the interface to make this happen.</p>
<p>The <strong>proc</strong> pseudo-file system is used as an interface to kernel data structures.  It is commonly mounted at /proc and most of the files inside are read-only. Within proc there exists a subdirectory for every running process on the system identified by its <strong>process ID</strong> (<strong>PID</strong>). </p>
<p>Inside each process directory is an <strong>environ</strong> file which contains the current environment for that process.</p>
<p><strong>/proc/&lt;PID&gt;/environ</strong></p>
<p>This file is limited at this point in time to 4096 characters. Therefore if you have a process with an unusually large environment the data beyond this limit will be truncated.</p>
<p>The environment variable entries are separated by <strong>null</strong> characters &#8216;<strong>\0</strong>&#8216;, which makes it difficult to view the file.  The best way to get around this is with the <strong>tr</strong> command which will replace the the null characters with <strong>newline</strong> characters &#8216;<strong>\n</strong>&#8216;.</p>
<pre>
$ cat /proc/12345/environ | tr "\000" "\n"
</pre>


<p>Related posts<ol><li><a href='http://www.wiredrevolution.com/system-administration/view-system-information-with-proccpuinfo-and-procmeminfo' rel='bookmark' title='Permanent Link: View system information with /proc/cpuinfo and /proc/meminfo'>View system information with /proc/cpuinfo and /proc/meminfo</a></li>
<li><a href='http://www.wiredrevolution.com/bash-programming/find-the-pid-of-a-background-child-process-in-bash' rel='bookmark' title='Permanent Link: Find the PID of a background child process in Bash'>Find the PID of a background child process in Bash</a></li>
<li><a href='http://www.wiredrevolution.com/system-administration/how-to-release-the-linux-disk-cache' rel='bookmark' title='Permanent Link: How to release the Linux disk cache'>How to release the Linux disk cache</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.wiredrevolution.com/system-administration/view-process-environment-details-with-proc/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Command substitution in BASH</title>
		<link>http://www.wiredrevolution.com/bash-programming/command-substitution-in-bash?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=command-substitution-in-bash</link>
		<comments>http://www.wiredrevolution.com/bash-programming/command-substitution-in-bash#comments</comments>
		<pubDate>Fri, 07 Nov 2008 13:42:59 +0000</pubDate>
		<dc:creator>Ryan</dc:creator>
				<category><![CDATA[bash]]></category>
		<category><![CDATA[backquote]]></category>
		<category><![CDATA[backtick]]></category>
		<category><![CDATA[BASH]]></category>
		<category><![CDATA[command]]></category>
		<category><![CDATA[environment variable]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[substitution]]></category>

		<guid isPermaLink="false">http://www.wiredrevolution.com/?p=628</guid>
		<description><![CDATA[<img src="http://www.wiredrevolution.com/wp-content/uploads/bash_icon.png" width="80" height="34" alt="" title="bash" /><br/>BASH has the ability to execute a command string and replace that string with the output of the command. Or to say it another way, the output of a command will replace the command itself. There are 2 ways to accomplish this. The first is to surround the command with backticks or blockquotes. `command` You [...]


Related posts<ol><li><a href='http://www.wiredrevolution.com/bash-programming/customize-the-bash-ps1-command-prompt' rel='bookmark' title='Permanent Link: Customize the BASH PS1 command prompt'>Customize the BASH PS1 command prompt</a></li>
<li><a href='http://www.wiredrevolution.com/bash-programming/single-versus-double-quotes-in-bash' rel='bookmark' title='Permanent Link: Single versus double quotes in BASH'>Single versus double quotes in BASH</a></li>
<li><a href='http://www.wiredrevolution.com/commands/search-for-files-with-the-find-command' rel='bookmark' title='Permanent Link: Search for files with the find command'>Search for files with the find command</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<img src="http://www.wiredrevolution.com/wp-content/uploads/bash_icon.png" width="80" height="34" alt="" title="bash" /><br/><p>BASH has the ability to execute a command string and replace that string with the output of the command. Or to say it another way, the output of a command will replace the command itself.</p>
<p>There are 2 ways to accomplish this.</p>
<p>The first is to surround the command with backticks or blockquotes.<br />
<strong>`command`</strong></p>
<p>You can also substitute with dollar symbol and parenthesis.<br />
<strong>$(command)</strong></p>
<p>The following will do a direct substitution of the current username on the command line.</p>
<pre>
$ echo /home/$(whoami)
</pre>
<pre>
/home/ryan
</pre>
<p>Another great use is the ability to assign a command to an environment variable.</p>
<pre>
$ MYDATE=`date`
</pre>
<p>or using the other format</p>
<pre>
$ MYDATE=$(date)
</pre>


<p>Related posts<ol><li><a href='http://www.wiredrevolution.com/bash-programming/customize-the-bash-ps1-command-prompt' rel='bookmark' title='Permanent Link: Customize the BASH PS1 command prompt'>Customize the BASH PS1 command prompt</a></li>
<li><a href='http://www.wiredrevolution.com/bash-programming/single-versus-double-quotes-in-bash' rel='bookmark' title='Permanent Link: Single versus double quotes in BASH'>Single versus double quotes in BASH</a></li>
<li><a href='http://www.wiredrevolution.com/commands/search-for-files-with-the-find-command' rel='bookmark' title='Permanent Link: Search for files with the find command'>Search for files with the find command</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.wiredrevolution.com/bash-programming/command-substitution-in-bash/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to correctly use LD_LIBRARY_PATH</title>
		<link>http://www.wiredrevolution.com/system-administration/how-to-correctly-use-ld_library_path?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-correctly-use-ld_library_path</link>
		<comments>http://www.wiredrevolution.com/system-administration/how-to-correctly-use-ld_library_path#comments</comments>
		<pubDate>Wed, 22 Oct 2008 12:32:13 +0000</pubDate>
		<dc:creator>Ryan</dc:creator>
				<category><![CDATA[system administration]]></category>
		<category><![CDATA[BASH]]></category>
		<category><![CDATA[bashrc]]></category>
		<category><![CDATA[dynamic library]]></category>
		<category><![CDATA[ELF]]></category>
		<category><![CDATA[environment variable]]></category>
		<category><![CDATA[ldd]]></category>
		<category><![CDATA[LD_LIBRARY_PATH]]></category>

		<guid isPermaLink="false">http://www.wiredrevolution.com/?p=453</guid>
		<description><![CDATA[<img src="http://www.wiredrevolution.com/wp-content/uploads/sysadmin_icon.png" width="80" height="94" alt="" title="system administration" /><br/>The LD_LIBRARY_PATH environment variable contains a colon separated list of paths that the linker uses to resolve library dependencies of ELF executables at run-time. These paths will be given priority over the standard library paths /lib and /usr/lib. The standard paths will still be searched, but only after the list of paths in LD_LIBRARY_PATH has [...]


Related posts<ol><li><a href='http://www.wiredrevolution.com/commands/view-dynamic-library-dependencies-with-ldd' rel='bookmark' title='Permanent Link: View dynamic library dependencies with ldd'>View dynamic library dependencies with ldd</a></li>
<li><a href='http://www.wiredrevolution.com/system-administration/select-threading-implementation-using-ld_assume_kernel' rel='bookmark' title='Permanent Link: Select threading implementation using LD_ASSUME_KERNEL'>Select threading implementation using LD_ASSUME_KERNEL</a></li>
<li><a href='http://www.wiredrevolution.com/guides/how-to-get-boxee-to-correctly-identify-local-media-files' rel='bookmark' title='Permanent Link: How to get Boxee to correctly identify local media files'>How to get Boxee to correctly identify local media files</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<img src="http://www.wiredrevolution.com/wp-content/uploads/sysadmin_icon.png" width="80" height="94" alt="" title="system administration" /><br/><p>The LD_LIBRARY_PATH environment variable contains a colon separated list of paths that the linker uses to resolve library dependencies of ELF executables at run-time. These paths will be given priority over the standard library paths <strong>/lib</strong> and <strong>/usr/lib</strong>.  The standard paths will still be searched, but only after the list of paths in LD_LIBRARY_PATH has been exhausted.</p>
<p>The best way to use LD_LIBRARY_PATH is to set it on the command line or script immediately before executing the program. This way you can keep the new LD_LIBRARY_PATH isolated from the rest of your system.</p>
<pre>
$ export LD_LIBRARY_PATH="/list/of/library/paths:/another/path"
$ ./program
</pre>
<p>In general it is not a good practice to have LD_LIBRARY_PATH permanently set in your environment. This could lead to unintended side effects as programs can link to unintended libraries producing strange results or unexpectedly crashing. There is also the possibility introducing potential security threats. </p>
<p>All those warnings aside, if you are using BASH you can set it permanently by placing a line similar to this in your <strong>.bashrc</strong> in your home directory.</p>
<pre>
export LIBRARY_PATH="/list/of/library/paths:/another/path"
</pre>
<p>A common case for setting LD_LIBRARY_PATH is when you have an application that requires dynamic libraries which were not installed in the standard library locations.</p>
<p>You can check if the linker can locate all the required libraries by <a href="http://www.wiredrevolution.com/commands/view-dynamic-library-dependencies-with-ldd">running the ldd command</a>.</p>
<pre>
$ ldd ~/myprogram
</pre>
<pre>
	librt.so.1 => /lib/librt.so.1 (0x00002b4eca08e000)
	libc.so.6 => /lib/libc.so.6 (0x00002b4eca49f000)
	libpthread.so.0 => /lib/libpthread.so.0 (0x00002b4eca7df000)
	/lib64/ld-linux-x86-64.so.2 (0x00002b4ec9e72000)
	libmylib.so.1 => not found
</pre>
<p>The linker cannot find libmylib.so.1. </p>
<p>Let&#8217;s assume this library exists here &#8220;~/myprogdir/lib/libmylib.so.1&#8243;. We have to set LD_LIBRARY_PATH to include this path for the application to successfully run.</p>
<pre>
$ export LD_LIBRARY_PATH="~/myprogdir/lib/:$LD_LIBRARY_PATH"
$ ldd ~/myprogram
</pre>
<pre>
	librt.so.1 => /lib/librt.so.1 (0x00002b4eca08e000)
	libc.so.6 => /lib/libc.so.6 (0x00002b4eca49f000)
	libpthread.so.0 => /lib/libpthread.so.0 (0x00002b4eca7df000)
	/lib64/ld-linux-x86-64.so.2 (0x00002b4ec9e72000)
	libmylib.so.1 => ~/myprogdir/lib/libmylib.so.1 (0x00002b4eca9fa000)
</pre>
<p>The linker has now found all the required libraries.</p>


<p>Related posts<ol><li><a href='http://www.wiredrevolution.com/commands/view-dynamic-library-dependencies-with-ldd' rel='bookmark' title='Permanent Link: View dynamic library dependencies with ldd'>View dynamic library dependencies with ldd</a></li>
<li><a href='http://www.wiredrevolution.com/system-administration/select-threading-implementation-using-ld_assume_kernel' rel='bookmark' title='Permanent Link: Select threading implementation using LD_ASSUME_KERNEL'>Select threading implementation using LD_ASSUME_KERNEL</a></li>
<li><a href='http://www.wiredrevolution.com/guides/how-to-get-boxee-to-correctly-identify-local-media-files' rel='bookmark' title='Permanent Link: How to get Boxee to correctly identify local media files'>How to get Boxee to correctly identify local media files</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.wiredrevolution.com/system-administration/how-to-correctly-use-ld_library_path/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Customize the BASH PS1 command prompt</title>
		<link>http://www.wiredrevolution.com/bash-programming/customize-the-bash-ps1-command-prompt?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=customize-the-bash-ps1-command-prompt</link>
		<comments>http://www.wiredrevolution.com/bash-programming/customize-the-bash-ps1-command-prompt#comments</comments>
		<pubDate>Sun, 19 Oct 2008 14:45:22 +0000</pubDate>
		<dc:creator>Ryan</dc:creator>
				<category><![CDATA[bash]]></category>
		<category><![CDATA[BASH]]></category>
		<category><![CDATA[bashrc]]></category>
		<category><![CDATA[codes]]></category>
		<category><![CDATA[color]]></category>
		<category><![CDATA[command prompt]]></category>
		<category><![CDATA[environment variable]]></category>
		<category><![CDATA[format]]></category>
		<category><![CDATA[PS1]]></category>

		<guid isPermaLink="false">http://www.wiredrevolution.com/?p=403</guid>
		<description><![CDATA[<img src="http://www.wiredrevolution.com/wp-content/uploads/bash_icon.png" width="80" height="34" alt="" title="bash" /><br/>The PS1 environment controls the appearance of the BASH command line prompt. There are a variety of default prompts but they usually include username, hostname, and working directory. You can easily customize your prompt to display information important to you as well as add color and style formatting. Here we can see the default prompt [...]


Related posts<ol><li><a href='http://www.wiredrevolution.com/bash-programming/command-substitution-in-bash' rel='bookmark' title='Permanent Link: Command substitution in BASH'>Command substitution in BASH</a></li>
<li><a href='http://www.wiredrevolution.com/bash-programming/have-a-bash-script-determine-its-own-location' rel='bookmark' title='Permanent Link: Have a Bash script determine it&#8217;s own location'>Have a Bash script determine it&#8217;s own location</a></li>
<li><a href='http://www.wiredrevolution.com/bash-programming/find-the-pid-of-a-background-child-process-in-bash' rel='bookmark' title='Permanent Link: Find the PID of a background child process in Bash'>Find the PID of a background child process in Bash</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<img src="http://www.wiredrevolution.com/wp-content/uploads/bash_icon.png" width="80" height="34" alt="" title="bash" /><br/><p>The <strong>PS1</strong> environment controls the appearance of the BASH command line prompt. There are a variety of default prompts but they usually include username, hostname, and working directory. You can easily customize your prompt to display information important to you as well as add color and style formatting.</p>
<p>Here we can see the default prompt is &#8220;username@hostname working_directory $&#8221;. </p>
<pre>
ryan@workstation ~ $
</pre>
<p>You can echo the PS1 environment variable and see the character codes which are used to create the output.</p>
<pre>
ryan@workstation ~ $ echo $PS1
</pre>
<pre>
\u@\h \w \$
</pre>
<p>Here is a list of all the special character codes you can use to build your PS1 command prompt.</p>
<h3>Special Character Codes</h3>
<p><strong>\a</strong> &#8211; an ASCII bell character (07)<br />
<strong>\d</strong> &#8211; the date in &#8220;Weekday Month Date&#8221; format (e.g., &#8220;Tue May 26&#8243;)<br />
<strong>\D{format}</strong> &#8211; the format is passed to strftime(3) and the result is inserted into the prompt string; an empty format results in a locale-specific time representation. The braces are required<br />
<strong>\e</strong> &#8211; an ASCII escape character (033)<br />
<strong>\h</strong> &#8211; the hostname up to the first `.&#8217;<br />
<strong>\H</strong> &#8211; the hostname<br />
<strong>\j</strong> &#8211; the number of jobs currently managed by the shell<br />
<strong>\l</strong> &#8211; the basename of the shell&#8217;s terminal device name<br />
<strong>\n</strong> &#8211; newline<br />
<strong>\r</strong> &#8211; carriage return<br />
<strong>\s</strong> &#8211; the name of the shell, the basename of $0 (the portion following the final slash)<br />
<strong>\t</strong> &#8211; the current time in 24-hour HH:MM:SS format<br />
<strong>\T</strong> &#8211; the current time in 12-hour HH:MM:SS format<br />
<strong>\@</strong> &#8211; the current time in 12-hour am/pm format<br />
<strong>\A</strong> &#8211; the current time in 24-hour HH:MM format<br />
<strong>\u</strong> &#8211; the username of the current user<br />
<strong>\v</strong> &#8211; the version of bash (e.g., 2.00)<br />
<strong>\V</strong> &#8211; the release of bash, version + patchelvel (e.g., 2.00.0)<br />
<strong>\w</strong> &#8211; the current working directory<br />
<strong>\W</strong> &#8211; the basename of the current working directory<br />
<strong>\!</strong> &#8211; the history number of this command<br />
<strong>\#</strong> &#8211; the command number of this command<br />
<strong>\$</strong> &#8211; if the effective UID is 0, a #, otherwise a $<br />
<strong>\nnn</strong> &#8211; the character corresponding to the octal number nnn<br />
<strong>\\</strong> &#8211; a backslash<br />
<strong>\[</strong> - begin a sequence of non-printing characters, which could be used to embed a terminal control sequence into the prompt<br />
<strong>\]</strong> &#8211; end a sequence of non-printing characters </p>
<p>Lets try a simple change. Make sure you use <a href="http://www.wiredrevolution.com/programming/bash-programming/single-versus-double-quotes-in-bash">double quotes</a> so the escape characters get passed on to the variable and not expanded in the shell.</p>
<pre>
ryan@workstation ~ $ PS1="My Prompt: $ "
</pre>
<pre>
My Prompt: $
</pre>
<p>As you can see the prompt will immediately change to reflect the changes.</p>
<p>We can add the date to the prompt.</p>
<pre>
ryan@workstation ~ $ PS1="\d \u@\h \w \$ "
</pre>
<pre>
Sun Oct 19 ryan@workstation ~ $
</pre>
<p>Now lets add some color to our original prompt.</p>
<pre>
ryan@workstation ~ $ PS1="\[\e[1;32m\]\u@\h\[\e[1;34m\] \w \$\[\e[0m\] "
</pre>
<p>Let go over this in detail.</p>
<p>A style block will display all text that follows with the style it defines. The block contains 3 elements.</p>
<p>Lets look at the first block.<br />
&#8220;\[\e[1;32m\]&#8221;</p>
<p>&#8220;<strong>\[</strong>" - begin a sequence of non-printing characters<br />
"<strong>\e[1;32m</strong>" - the semicolon separated list of style/color codes (in this case <strong>bold;green</strong>)<br />
"<strong>\]</strong>&#8221; &#8211; end a sequence of non-printing characters</p>
<p>The first block will display the following <em>username@hostname</em> text in BOLD green.<br />
&#8220;<strong>\[\e[1;32m\]</strong>\u@\h\[\e[1;34m\] \w \$\[\e[0m\] &#8221;</p>
<p>The second block will display the following <em>working_directory</em> text in BOLD blue.<br />
&#8220;\[\e[1;32m\]\u@\h<strong>\[\e[1;34m\]</strong> \w \$\[\e[0m\] &#8221;</p>
<p>The final block resets the colors.<br />
&#8220;\[\e[1;32m\]\u@\h\[\e[1;34m\] \w \$<strong>\[\e[0m\]</strong> &#8221;</p>
<p>Here is a rundown of all the color and style codes.</p>
<h3>Color and Style Codes</h3>
<p><strong>Style</strong><br />
0 &#8211; default<br />
1 &#8211; bold<br />
4 &#8211; underline<br />
7 &#8211; inverse<br />
9 &#8211; strikeout</p>
<p><strong>Foreground Colors</strong><br />
30 &#8211; foreground Black<br />
31 &#8211; foreground Red<br />
32 &#8211; foreground Green<br />
33 &#8211; foreground Yellow<br />
34 &#8211; foreground Blue<br />
35 &#8211; foreground Magenta<br />
36 &#8211; foreground Cyan<br />
37 &#8211; foreground White</p>
<p><strong>Background Colors</strong><br />
40 &#8211; background Black<br />
41 &#8211; background Red<br />
42 &#8211; background Green<br />
43 &#8211; background Yellow<br />
44 &#8211; background Blue<br />
45 &#8211; background Magenta<br />
46 &#8211; background Cyan<br />
47 &#8211; background White</p>
<p>You can combine multiple codes to create the exact style you want.<br />
&#8220;\[\e[1;4;36;47m\]&#8221;<br />
This style block defines bold and underlined cyan text with a white background. </p>
<p>To make these changes permanent place your new prompt string like the one below in your <strong>~/.bashrc</strong> file in your home directory. </p>
<pre>
PS1="\[\e[1;32m\]\u@\h\[\e[1;34m\] \w \$ \[\e[0m\]"
</pre>
<p>This file is sourced every time you start a new interactive shell.</p>


<p>Related posts<ol><li><a href='http://www.wiredrevolution.com/bash-programming/command-substitution-in-bash' rel='bookmark' title='Permanent Link: Command substitution in BASH'>Command substitution in BASH</a></li>
<li><a href='http://www.wiredrevolution.com/bash-programming/have-a-bash-script-determine-its-own-location' rel='bookmark' title='Permanent Link: Have a Bash script determine it&#8217;s own location'>Have a Bash script determine it&#8217;s own location</a></li>
<li><a href='http://www.wiredrevolution.com/bash-programming/find-the-pid-of-a-background-child-process-in-bash' rel='bookmark' title='Permanent Link: Find the PID of a background child process in Bash'>Find the PID of a background child process in Bash</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.wiredrevolution.com/bash-programming/customize-the-bash-ps1-command-prompt/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Select threading implementation using LD_ASSUME_KERNEL</title>
		<link>http://www.wiredrevolution.com/system-administration/select-threading-implementation-using-ld_assume_kernel?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=select-threading-implementation-using-ld_assume_kernel</link>
		<comments>http://www.wiredrevolution.com/system-administration/select-threading-implementation-using-ld_assume_kernel#comments</comments>
		<pubDate>Mon, 13 Oct 2008 12:37:09 +0000</pubDate>
		<dc:creator>Ryan</dc:creator>
				<category><![CDATA[system administration]]></category>
		<category><![CDATA[ABI]]></category>
		<category><![CDATA[environment variable]]></category>
		<category><![CDATA[glibc]]></category>
		<category><![CDATA[kernel]]></category>
		<category><![CDATA[LD_ASSUME_KERNEL]]></category>
		<category><![CDATA[LinuxThreads]]></category>
		<category><![CDATA[NPTL]]></category>
		<category><![CDATA[threads]]></category>

		<guid isPermaLink="false">http://www.wiredrevolution.com/?p=273</guid>
		<description><![CDATA[<img src="http://www.wiredrevolution.com/wp-content/uploads/sysadmin_icon.png" width="80" height="94" alt="" title="system administration" /><br/>For backwards compatibility, many Linux distributions support both the older LinuxThreads implementation as well as the newer Native POSIX Thread Library (NPTL). By setting the LD_ASSUME_KERNEL environment variable you can tell the dynamic linker to assume that it is running on top of a particular kernel version. This will override the dynamic linker&#8217;s default choice [...]


Related posts<ol><li><a href='http://www.wiredrevolution.com/system-administration/how-to-correctly-use-ld_library_path' rel='bookmark' title='Permanent Link: How to correctly use LD_LIBRARY_PATH'>How to correctly use LD_LIBRARY_PATH</a></li>
<li><a href='http://www.wiredrevolution.com/commands/view-dynamic-library-dependencies-with-ldd' rel='bookmark' title='Permanent Link: View dynamic library dependencies with ldd'>View dynamic library dependencies with ldd</a></li>
<li><a href='http://www.wiredrevolution.com/virtualbox/virtualbox-4-0-upgrade-and-the-oracle-vm-virtualbox-extension-pack' rel='bookmark' title='Permanent Link: VirtualBox 4.0 upgrade and the Oracle VM VirtualBox Extension Pack'>VirtualBox 4.0 upgrade and the Oracle VM VirtualBox Extension Pack</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<img src="http://www.wiredrevolution.com/wp-content/uploads/sysadmin_icon.png" width="80" height="94" alt="" title="system administration" /><br/><p>For backwards compatibility, many Linux distributions support both the older LinuxThreads implementation as well as the newer Native POSIX Thread Library (NPTL). By setting the LD_ASSUME_KERNEL environment variable you can tell the dynamic linker to assume that it is running on top of a particular kernel version.  This will override the dynamic linker&#8217;s default choice of threading implementation (usually NPTL) and force the use of the older LinuxThreads implementation at run-time. </p>
<p>Many 32-bit systems have 3 separate glibc versions which have support for a minimum OS Application Binary Interface (ABI), designated by a kernel version and offer support for a particular thread implementation.</p>
<p><strong>/lib/tls/libc.so.6</strong> </p>
<ul>
<li>minimum ABI = 2.4.20</li>
<li>Native POSIX Thread Library (NPTL)</li>
</ul>
<p><strong>/lib/i686/libc.so.6</strong> </p>
<ul>
<li>minimum ABI = 2.4.1</li>
<li>standard LinuxThreads</li>
</ul>
<p><strong>/lib/libc.so.6</strong> </p>
<ul>
<li>minimum ABI = 2.2.5</li>
<li>early LinuxThreads code which had fixed size threads</li>
</ul>
<p>It is worth noting that 64-bit systems do not support the older 2.2.5 LinuxThreads implementation.</p>
<p>You can run the following commands to see what thread implementations are supported by each separate glibc library.</p>
<pre>
$ /lib/tls/libc.so.6 | grep [T|t]hreads
</pre>
<pre>
	Native POSIX Threads Library by Ulrich Drepper
</pre>
<pre>
$ /lib/i686/libc.so.6 | grep [T|t]hreads
</pre>
<pre>
	linuxthreads-0.10 by Xavier Leroy
</pre>
<pre>
$ /lib/libc.so.6 | grep [T|t]hreads
</pre>
<pre>
	linuxthreads-0.10 by Xavier Leroy
</pre>
<p>A shared library can tell the dynamic linker which minimum OS ABI version is needed for it to successfully run. At run-time the linker will start at the most recent library path and walk backwards in this order: <strong>/lib/tls</strong>, <strong>/lib/i686</strong>, <strong>/lib</strong>.  It will either link to the first library it finds or fail and terminate the program if the minimum ABI is reached before it finds a library.</p>
<p>Setting LD_ASSUME_KERNEL below the minimum threshold ABI version of any dynamic library will cause the linker to skip that library and try to find an older implementation</p>
<p>Set the environment variable by assigning it to a specific ABI/kernel version.</p>
<pre>
$ export LD_ASSUME_KERNEL=X.Y.Z
</pre>
<p>You must be careful not to set the the ABI below 2.2.5 in your environment as all programs which require dynamic linking will probably fail to run.  Luckily you are still be able to unset or change it back.</p>
<p>It is useless to set LD_ASSUME_KERNEL for most programs as they will run correctly no matter what underlying implementation is used since the API is the same. However there are some programs that may depend on some non-conformant behavior requiring LinuxThreads, which will fail with NPTL.</p>


<p>Related posts<ol><li><a href='http://www.wiredrevolution.com/system-administration/how-to-correctly-use-ld_library_path' rel='bookmark' title='Permanent Link: How to correctly use LD_LIBRARY_PATH'>How to correctly use LD_LIBRARY_PATH</a></li>
<li><a href='http://www.wiredrevolution.com/commands/view-dynamic-library-dependencies-with-ldd' rel='bookmark' title='Permanent Link: View dynamic library dependencies with ldd'>View dynamic library dependencies with ldd</a></li>
<li><a href='http://www.wiredrevolution.com/virtualbox/virtualbox-4-0-upgrade-and-the-oracle-vm-virtualbox-extension-pack' rel='bookmark' title='Permanent Link: VirtualBox 4.0 upgrade and the Oracle VM VirtualBox Extension Pack'>VirtualBox 4.0 upgrade and the Oracle VM VirtualBox Extension Pack</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.wiredrevolution.com/system-administration/select-threading-implementation-using-ld_assume_kernel/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

