>
only redirects standard out (stdout
), but when whatis
cannot find information about a file it writes that to a different stream, stderr
. You can redirect that as well with 2>
since stderr
is file handle 2. You can redirect both stdout and stderr like &>
or you could redirect stderr to stdout by doing2>&1
You can read all about redirection here
So in your example if you want all the errors as well as the success to end up in blah
you could do
whatis `ls /bin` &> blah
or, using the alternate subshell syntax that's preferred these days:
whatis $(ls /bin) &> blah
though /bin
isn't likely to have one though, be careful doing stuff like this. The results of ls /bin
will be subject to word splitting, so if any of the files there contain, say, spaces, they would be treated as different arguments to whatis
. This is why you're generally discouraged from parsing the output of ls
(see this question for a discussion of it)
you could do what you're trying differently like
find /bin -maxdepth 1 -type f -exec whatis {} + &> blah
which will look in /bin
and not go deeper (like the glob) then find just files (the type f
argument) and for each thing it finds it'll execute whatis
, then do the same redirection we had talked about.