<?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>sebthom.de &#187; bash</title>
	<atom:link href="http://sebthom.de/tag/bash/feed/" rel="self" type="application/rss+xml" />
	<link>http://sebthom.de</link>
	<description>Selbständiger IT Berater - Java, J2EE, WebSphere Portal, Lotus Domino</description>
	<lastBuildDate>Sat, 03 Sep 2011 18:02:12 +0000</lastBuildDate>
	<language>de</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Bash: Capturing stderr in a variable while still printing to the console.</title>
		<link>http://sebthom.de/158-bash-capturing-stderr-variable/lang/de/</link>
		<comments>http://sebthom.de/158-bash-capturing-stderr-variable/lang/de/#comments</comments>
		<pubDate>Mon, 31 Jan 2011 22:56:53 +0000</pubDate>
		<dc:creator>Sebastian Thomschke</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[stderr]]></category>
		<category><![CDATA[stdout]]></category>

		<guid isPermaLink="false">http://sebthom.de/?p=158</guid>
		<description><![CDATA[     <link rel="alternate" type="application/atom+xml" title="sebthom.de Category: IT" href="http://sebthom.de/category/it/lang/de/feed/" />
     <link rel="alternate" type="application/atom+xml" title="sebthom.de Category: Linux" href="http://sebthom.de/category/it/linux/lang/de/feed/" />
Storing the stdout output of a command in a variable and displaying it is simple: OUTPUT=$(command) echo $OUTPUT If you have longer running commands where you want to display stdout in realtime and also store it in a variable you can tee the output to stderr: OUTPUT=$(command &#124; tee /dev/stderr) OUTPUT=$(command &#124; tee /proc/self/fd/2) OUTPUT=$(command [...]]]></description>
			<content:encoded><![CDATA[<p>Storing the stdout output of a command in a variable and displaying it is simple:</p>
<pre class="perl" name="code">
OUTPUT=$(command)
echo $OUTPUT
</pre>
<p>If you have longer running commands where you want to display stdout in realtime and also store it in a variable you can tee the output to stderr:</p>
<pre class="perl" name="code">
OUTPUT=$(command | tee /dev/stderr)
</pre>
<pre class="perl" name="code">
OUTPUT=$(command | tee /proc/self/fd/2)
</pre>
<pre class="perl" name="code">
OUTPUT=$(command | tee >(cat - >&#038;2))
</pre>
<p>If you have longer running commands where you want to display stdout/stderr in realtime and also store stderr in a variable it gets a bit complicated.<br />
However, this can be achieved by switching stdout and stderr and then teeing the new stdout (which is stderr now) back to stderr for console output.</p>
<pre class="perl" name="code">
ERROR=$(command 3>&#038;1 1>&#038;2 2>&#038;3 | tee /dev/stderr)
</pre>
<pre class="perl" name="code">
ERROR=$(command 3>&#038;1 1>&#038;2 2>&#038;3 | tee /proc/self/fd/2)
</pre>
<pre name="code" class="bash">
ERROR=$(command 3>&#038;1 1>&#038;2 2>&#038;3 | tee >(cat - >&#038;2))
</pre>
<p>Good reading:<br />
<a href="http://mywiki.wooledge.org/BashFAQ/002">Bash FAQ: How can I store the return value/output of a command in a variable?</a></p>
 <img src="http://sebthom.de/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=158" width="1" height="1" style="display: none;" /><hr />
<p><small>&copy; sebthom for <a href="http://sebthom.de">sebthom.de</a>, 2011. |
<a href="http://sebthom.de/158-bash-capturing-stderr-variable/lang/de/">Permalink</a> |
<a href="http://sebthom.de/158-bash-capturing-stderr-variable/lang/de/#comments">No comment</a> |
Add to
<a href="http://del.icio.us/post?url=http://sebthom.de/158-bash-capturing-stderr-variable/lang/de/&amp;title=Bash: Capturing stderr in a variable while still printing to the console.">del.icio.us</a>
<br/>
Post tags: <a href="http://sebthom.de/tag/bash/" rel="nofollow tag">bash</a>, <a href="http://sebthom.de/tag/stderr/" rel="nofollow tag">stderr</a>, <a href="http://sebthom.de/tag/stdout/" rel="nofollow tag">stdout</a><br/>
</small></p>
<p><small>Feed enhanced by <a href='http://planetozh.com/blog/my-projects/wordpress-plugin-better-feed-rss/'>Better Feed</a> from  <a href='http://planetozh.com/blog/'>Ozh</a></small></p>
]]></content:encoded>
			<wfw:commentRss>http://sebthom.de/158-bash-capturing-stderr-variable/feed/lang/de/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Determine the user who logged on via SSH</title>
		<link>http://sebthom.de/134-determine-the-user-who-logged-on-via-ssh/lang/de/</link>
		<comments>http://sebthom.de/134-determine-the-user-who-logged-on-via-ssh/lang/de/#comments</comments>
		<pubDate>Mon, 23 Feb 2009 16:16:23 +0000</pubDate>
		<dc:creator>Sebastian Thomschke</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[username]]></category>

		<guid isPermaLink="false">http://sebthom.de/134-determine-the-user-who-logged-on-via-ssh/</guid>
		<description><![CDATA[Today we had the need to determine the initial id of a user who logged onto a Linux box via SSH and executed the su command. When the su command is issued the effective user is changed and whoami or id commands will report that new user id instead. For anyone who is interested, that [...]]]></description>
			<content:encoded><![CDATA[<p>Today we had the need to determine the initial id of a user who logged onto a Linux box via SSH and executed the <b>su</b> command. When the <b>su</b> command is issued the effective user is changed and <b>whoami</b> or <b>id</b> commands will report that new user id instead.</p>
<p>For anyone who is interested, that is what we came up to put the initial user id into a variable named ${LOGIN_USER}</p>
<pre>LOGIN_USER=`who -m`; LOGIN_USER=${LOGIN_USER%% *}</pre>
<p>or alternatively</p>
<pre>LOGIN_USER=`who -m | cut -d' ' -f1`</pre>
 <img src="http://sebthom.de/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=134" width="1" height="1" style="display: none;" /><hr />
<p><small>&copy; sebthom for <a href="http://sebthom.de">sebthom.de</a>, 2009. |
<a href="http://sebthom.de/134-determine-the-user-who-logged-on-via-ssh/lang/de/">Permalink</a> |
<a href="http://sebthom.de/134-determine-the-user-who-logged-on-via-ssh/lang/de/#comments">No comment</a> |
Add to
<a href="http://del.icio.us/post?url=http://sebthom.de/134-determine-the-user-who-logged-on-via-ssh/lang/de/&amp;title=Determine the user who logged on via SSH">del.icio.us</a>
<br/>
Post tags: <a href="http://sebthom.de/tag/bash/" rel="nofollow tag">bash</a>, <a href="http://sebthom.de/tag/linux/" rel="nofollow tag">Linux</a>, <a href="http://sebthom.de/tag/username/" rel="nofollow tag">username</a><br/>
</small></p>
<p><small>Feed enhanced by <a href='http://planetozh.com/blog/my-projects/wordpress-plugin-better-feed-rss/'>Better Feed</a> from  <a href='http://planetozh.com/blog/'>Ozh</a></small></p>
]]></content:encoded>
			<wfw:commentRss>http://sebthom.de/134-determine-the-user-who-logged-on-via-ssh/feed/lang/de/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

