What is the function of following UNIX command ? WC – l b &
2016
What is the function of following UNIX command ?
WC – l b &
- A.
It runs the word count program to count the number of lines in its input, a, writing the result to b, as a foreground process.
- B.
It runs the word count program to count the number of lines in its input, a, writing the result to b, but does it in the background.
- C.
It counts the errors during the execution of a process, a, and puts the result in process b.
- D.
It copies the ‘l’ numbers of lines of program from file, a, and stores in file b.
Attempted by 45 students.
Show answer & explanation
Correct answer: B
Key points: how the wc -l command and the ampersand (&) behave.
wc -l counts the number of lines in each file passed as an argument and prints the count(s) to standard output.
If you provide multiple filenames, wc prints a line count for each file and a total line count.
The ampersand (&) at the end runs the command in the background (so the shell prompt returns immediately).
Output is sent to standard output by default. To write output into a file you must use output redirection, for example: wc -l a > b &
Therefore, the literal command wc -l a b & counts lines in files a and b, prints counts (and a total) to standard output, and runs in the background. If the intended action was to write the result into file b, the correct command would include redirection, e.g. wc -l a > b &.