On Sat, Sep 28, 2019 at 04:01:27PM +1000, David wrote: > > Maybe better to hide the stdout from md5sum: > > # find junk -xdev -type f -exec md5sum '{}' >/dev/null \; > > To be more precise, that hides the stdout from both md5sum and find, > but I don't think that matters to the goal.
This is correct. Pedantry follows: The >/dev/null redirection applies to the "simple" shell command in which it occurs, which happens to be find. Its position within that simple shell command is irrelevant. It could be at the end, at the beginning, or somewhere in the middle. In this case, it happens to be in the middle. The command is 100% equivalent to: find junk -xdev -type f -exec md5sum '{}' \; >/dev/null find's stdout is redirected to /dev/null, and if find happens to find any files which meet its matching criteria, and executes md5sum to operate on them, md5sum will inherit find's stdout, which will still be pointed to /dev/null. The freedom to place a redirection anywhere within a simple shell command is why examples like this one: [ "$i" > 5 ] give such surprising results. This is a simple shell command (the command name is "["), with an output redirection in it. It is 100% equivalent to [ "$i" ] > 5 which opens-and-truncates a file named "5" for stdout, then performs a string-length test on the value of "$i". The command's exit status will be "true" (0) as long as "$i" is not empty. The intended command is most likely: [ "$i" -gt 5 ] which treats the value of "$i" as an integer, and then checks whether that integer is greater than 5. It returns "true" (0) if the value is greater than 5, returns "false" (1) if it's less than or equal to 5, and returns a value greater than 1 (still "false") and writes an error message to stderr if "$i" cannot be converted to an integer.