1

Do the following and it works

~$whatis `ls /bin`
stty (1)             - change and print terminal line settings

stty (2)             - unimplemented system calls

su (1)               - change user ID or become superuser

etc...

redirect the output to a file and I get this ?

~$ whatis `ls /bin` > blah

kmod: nothing appropriate.

ntfsck: nothing appropriate.
Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232
  • Thanks for the comments guy. my dumb self did not check to see if the stdout actually went to the blah file , which it did and i guess seeing the stderr threw me off. good reiteration of redirection of the streams. – ssvegeta96 Nov 03 '16 at 18:00

2 Answers2

1

> 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.

Eric Renouf
  • 18,431
0

whatis searches a set of database files containing short descriptions of system commands for keywords and displays the result on the standard output. Only complete word matches are displayed.

kmod: nothing appropriate. is a message tells that, it didnt find anything for kmod.

if you want to redirect all the output, then try this..

whatis $(ls /bin) > /tmp/a.txt
Kamaraj
  • 4,365
  • redirecting stdout is exactly what they did; I think you missed the part where whatis wrote to stderr, which wasn't captured by the redirection of stdout. – Jeff Schaller Nov 03 '16 at 14:36