How to pass outputs from multiple commands as inputs for another command?

0

I'd like to pipe the outputs of multiple shell commands as inputs for another command.

For example:

>>> ls
folder1
folder2

>>> ls folder1
file1
file2

>>> ls folder2
file1
file2
file3

>>> ls folder1 > out1.txt; ls folder2 > out2.txt; diff out1.txt out2.txt
2a3
> file3

In the above example, I have to save this outputs of the 2 ls commands into separate files then compare them with diff. I'd like to be able to compare the 2 folders in a single line without having to create extra folders/files.

The following I've tried don't work:

>>> diff ("ls folder1") ("ls folder2")
>>> diff < ("ls folder1") ("ls folder2")
>>> ("ls folder1") ("ls folder2") | diff

... and I'd like something like that.

Not just with diff, but I'd like something to pipe any number of outputs as inputs without creating new folders/files.

John Zhau

Posted 2019-10-22T04:02:51.797

Reputation: 137

1Research "process substitution". – Kamil Maciorowski – 2019-10-22T04:33:17.313

OK that pretty much got me my answer. Couldn't figure it out because I didn't know of that. – John Zhau – 2019-10-22T04:50:46.750

No answers