<div dir="ltr">It is surprisingly flexible.  Below I save the place file descriptor one is going to by using file descriptor six.  (The convention in UNIX-like systems is for file descriptor zero to be standard input, file descriptor one to be standard output, and file descriptor two to be standard error.  For interactive shell sessions, all three are connected to the terminal at first.)<div><br></div><div>Then I redirect standard output to a file named, &quot;output&quot;, and write to it just by doing a regular &quot;echo&quot; command.  When I try to cat the file, it doesn&#39;t work, because it would be an infinite loop, I suppose!  So I put standard output back by restoring the &quot;backup&quot; from file descriptor six.<br><div><br></div><div>In the example, I take advantage of the fact that you can redirect the current shell&#39;s file descriptors by using &quot;exec&quot;.</div><div><br></div><div><div>ecashin@montgomery:~/tmp$ sh</div><div>$ exec 6&gt;&amp;1</div><div>$ exec 1&gt;output</div><div>$ echo hi there</div><div>$ cat output</div><div>cat: output: input file is output file</div><div>$ exec 1&gt;&amp;6</div><div>$ cat output</div><div>hi there</div><div>$ </div></div><div><br></div><div>You can redirect input as well, but it has never been easy for me to remember the syntax, and it didn&#39;t feel as useful and smooth an experience to use that feature.</div><div><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, May 13, 2017 at 3:49 PM, Byron Jeff <span dir="ltr">&lt;<a href="mailto:byronjeff@clayton.edu" target="_blank">byronjeff@clayton.edu</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Sat, May 13, 2017 at 02:30:15PM -0400, Pete Hardie wrote:<br>
&gt;    If memory serves, it means to redirect stderr to the same place a<br>
&gt;    stdout.  Useful when you want all the output (normal and error) to go<br>
&gt;    to the same file/pipe<br>
<br>
</span>Sort of. The left hand side is the target while the right hand side is the<br>
source. Technically redirecting stderr to stdout is:<br>
<br>
2&gt;&amp;1<br>
<br>
2 is stderr and the source. So that redirects stderr to the same place as<br>
stdout. Narahari specified the opposite:<br>
<br>
echo ... &gt;&amp;2<br>
<br>
Here stdout is the source because it&#39;s the default, stderr is the target.<br>
<br>
In the end they both accomplish the same goal, which is getting both stdout<br>
and stderr to the same place. The difference is that often stdout is<br>
already redirected whereas typically stderr is generally attached to the<br>
screen. So the goal of the second is to ensure that the echo output goes to<br>
the screen even if stdout overall for the script is redirected to a file,<br>
whereas the first one guarantees that if stdout is already redirected, that<br>
the error messages also follow that redirection.<br>
<br>
BAJ<br>
<span class=""><br>
&gt;<br>
&gt;    On Sat, May 13, 2017 at 2:11 PM, Narahari &#39;n&#39; Savitha<br>
</span><span class="">&gt;    &lt;[1]<a href="mailto:savithari@gmail.com">savithari@gmail.com</a>&gt; wrote:<br>
&gt;<br>
&gt;    Friends:<br>
&gt;    I see this in a sample code<br>
&gt; echo &quot;[statsgen] restarting myself&quot; &gt;&amp;2<br>
&gt;<br>
&gt;    What does the &gt;&amp;2 mean ?<br>
&gt;    -N<br>
&gt;<br>
&gt;      ______________________________<wbr>_________________<br>
&gt;      Ale mailing list<br>
</span>&gt;      [2]<a href="mailto:Ale@ale.org">Ale@ale.org</a><br>
&gt;      [3]<a href="http://mail.ale.org/mailman/listinfo/ale" rel="noreferrer" target="_blank">http://mail.ale.org/<wbr>mailman/listinfo/ale</a><br>
<span class="">&gt;      See JOBS, ANNOUNCE and SCHOOLS lists at<br>
</span>&gt;      [4]<a href="http://mail.ale.org/mailman/listinfo" rel="noreferrer" target="_blank">http://mail.ale.org/<wbr>mailman/listinfo</a><br>
<span class="">&gt;<br>
&gt;    --<br>
&gt;    Pete Hardie<br>
&gt;    --------<br>
&gt;    Better Living Through Bitmaps<br>
&gt;<br>
</span>&gt; References<br>
&gt;<br>
&gt;    1. mailto:<a href="mailto:savithari@gmail.com">savithari@gmail.com</a><br>
&gt;    2. mailto:<a href="mailto:Ale@ale.org">Ale@ale.org</a><br>
&gt;    3. <a href="http://mail.ale.org/mailman/listinfo/ale" rel="noreferrer" target="_blank">http://mail.ale.org/mailman/<wbr>listinfo/ale</a><br>
&gt;    4. <a href="http://mail.ale.org/mailman/listinfo" rel="noreferrer" target="_blank">http://mail.ale.org/mailman/<wbr>listinfo</a><br>
<span class=""><br>
&gt; ______________________________<wbr>_________________<br>
&gt; Ale mailing list<br>
&gt; <a href="mailto:Ale@ale.org">Ale@ale.org</a><br>
&gt; <a href="http://mail.ale.org/mailman/listinfo/ale" rel="noreferrer" target="_blank">http://mail.ale.org/mailman/<wbr>listinfo/ale</a><br>
&gt; See JOBS, ANNOUNCE and SCHOOLS lists at<br>
&gt; <a href="http://mail.ale.org/mailman/listinfo" rel="noreferrer" target="_blank">http://mail.ale.org/mailman/<wbr>listinfo</a><br>
<br>
<br>
--<br>
</span>Byron A. Jeff<br>
Associate Professor: Department of Computer Science and Information Technology<br>
College of Information and Mathematical Sciences<br>
Clayton State University<br>
<a href="http://faculty.clayton.edu/bjeff" rel="noreferrer" target="_blank">http://faculty.clayton.edu/<wbr>bjeff</a><br>
<div class="HOEnZb"><div class="h5">______________________________<wbr>_________________<br>
Ale mailing list<br>
<a href="mailto:Ale@ale.org">Ale@ale.org</a><br>
<a href="http://mail.ale.org/mailman/listinfo/ale" rel="noreferrer" target="_blank">http://mail.ale.org/mailman/<wbr>listinfo/ale</a><br>
See JOBS, ANNOUNCE and SCHOOLS lists at<br>
<a href="http://mail.ale.org/mailman/listinfo" rel="noreferrer" target="_blank">http://mail.ale.org/mailman/<wbr>listinfo</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">  Ed Cashin &lt;<a href="mailto:ecashin@noserose.net" target="_blank">ecashin@noserose.net</a>&gt;</div></div>
</div>