Read output of shell command from a file

From Notes_Wiki
Revision as of 13:35, 7 April 2022 by Saurabh (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Home > Shell scripting > Shell operators > Read output of shell command from a file

It is always possible to use normal shell redirect such as:

ls > 1.txt
ls -a > 2.txt
diff 1.txt 2.txt

to get output of a command in a file and then give it as path to some other command.

But the same can be achieved using:

diff <(ls) <(ls -a)

What happens under the hood, is that two output file descriptors of the given commands are given to diff as input. Use:

echo diff <(ls) <(ls -a)

to understand this.

Since file descriptors are used unless a command is ready to accept input from a file descriptor, it may not work.



Home > Shell scripting > Shell operators > Read output of shell command from a file