I am working on homework assignment. The last question the ls /bin | shuf -n 1
works to get a random command. But getting the whatis
command to read the output from that isn't working.
Asked
Active
Viewed 61 times
0

jww
- 97,681
- 90
- 411
- 885

anti_nugget
- 11
-
basically asking the what the command would be to print out "did you know that: *insert whatis command of [ Ls /bin | shuf -n 1 ]*" – anti_nugget Nov 17 '19 at 03:54
-
the one shown in the snip is what i have but its not working. the bold print is th question, everything else is my answer. – anti_nugget Nov 17 '19 at 03:55
-
I believe you want to use `xargs`. Something like `ls -1 /bin/ | shuf -n 1 | xargs whatis`. Or maybe `whatis $(ls -1 /bin/ | shuf -n 1)`. Also see [Get argument from pipe](https://stackoverflow.com/q/17847103/608639). – jww Nov 17 '19 at 05:21
1 Answers
0
Use echo -n
and subshell
echo -n "Did you know that " && whatis -s1,8 $(ls -1 /bin | shuf -n 1)
- OR the old way with backticks -
echo -n "Did you know that " && whatis -s1,8 `ls -1 /bin | shuf -n 1`
Comments:
ls -1
provides single line output
whatis -s1,8
limits man pages to sections 1 and 8

niry
- 3,238
- 22
- 34