Bash – “command | less” vs “less <(command)”

bashcommand-substitutionfile-descriptorslesspipe

A common "idiom" for viewing large amounts of command output is to pipe it to less, via command | less. However, it's also possible (perhaps only in bash, haven't tested in other shells) to use the less <(command) syntax, but less tends to complain /dev/fd/63 is not a regular file. After poking around in /proc/*/fd, I see that in both cases, it's reading from a pipe. The only difference is that in the first case, it's stdin being redirected. In the second case, it's getting /dev/fd/63 as a file name. Does less somehow "ignore" the regular file check when reading from stdin? Also, how does it determine that /dev/fd/63 isn't a regular file, even if the contents are text?

Best Answer

less normally refuses to open non regular files like pipes or also binaries. You can use the -f operator to force less to open non regular files:

less -f <(command)

Another approach is to use process substitution:

less < <(command)

This causes the pipe that was created with <() to act as standard input (STDIN) for less.

Related Question