also see this
and this
Here's a demo...make a file like this:
#!/bin/bash
echo "stderr" >&2
echo "stdout"
Then try these commands...
-
test (both print to console)
-
test | less (only shows stdout in less)
-
test 2>&1 | less (redirects stderr to stdout, so both show up in less)
-
test 1> /dev/null (redirects stdout to /dev/null, stderr still goes to console)
-
test 2> /dev/null (redirects stderr to /dev/null, stdout still goes to console)
-
test 2>&1 1> /dev/null (redirects stderr to stdout, and stdout to /dev/null. Note, this does not redirect the combined stderr/stdout you have also specified...it redirects JUST what would have been stdout)
from
here...some info on custom file descriptors
This is making a custom file descriptor with value three . this override the bash/shell default file descriptors. and save the current stdout value you can make it 4 6..9 .do not do 5 .
exec 3>&1
execute your command and pipe it to grep
command 2>&1 >&3 3>&- | grep word 3>&-
#1 2 3 4 5 6 7 8
1. your command
2. redirect the output at the default stdout
3. this will call the the saved value which u make for it save
4. close file descriptor 3 for 'grep'
5. the world famous pipe
6. grep #man grep for details
7. your needed words
8. close output file descriptor 3.
close the upper exec 3>&1 to resume work on your shell as defaults :
exec 3>&-
Diaa Radwan
--
MattWalsh - 28 Nov 2005