[Cialug] Having a "this should work" moment
Zachary Kotlarek
zach at kotlarek.com
Fri Oct 2 00:00:47 CDT 2009
On Oct 1, 2009, at 8:58 PM, Josh More wrote:
> The three streams are:
>
> 0) Standard Input
> 1) Standard Output
> 2) Standard Error
You can get additional descriptors if you do:
exec 3>&1
or:
exec 4<&0
And you can close descriptors with:
1>&-
or:
0<&-
if you've created extra descriptors or want to force one of the
standard ones to close.
Such tricks are occasionally handy if you're trying to see stdout
while piping stderr, or if you need to trick a program into thinking
that stdin is not available.
You can also redirect all stderr output to stdout for all the commands
in a shell script by adding the line:
exec 2>&1
to the top instead of adding 2>&1 to the end of each command.
Similarly you could add:
exec 1>>/var/log/script.out
and get all the output in a file, again without adding the redirect to
each command.
Zach
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2746 bytes
Desc: not available
Url : http://cialug.org/pipermail/cialug/attachments/20091002/e0613f28/attachment-0001.bin
More information about the Cialug
mailing list