Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Comments on When a command takes filenames as argument, how can I avoid creating temporary files?

Parent

When a command takes filenames as argument, how can I avoid creating temporary files?

+1
−0

Suppose I have a command that takes filenames as arguments, like: diff foo.txt bar.txt

What if instead of actual files, I want to use the results of a command in each?

I can use temporary files:

ls /home/alice > /tmp/alice.txt
ls /home/bob > /tmp/bob.txt
diff alice.txt bob.txt

But what if I don't want to create the files?

History
Why does this post require moderator attention?
You might want to add some details to your flag.
Why should this post be closed?

0 comment threads

Post
+5
−0

What you're looking for is called process substitution.

In Bash and many bash-like shells, you can use <(foo_command --with --arguments) instead of the file path:

diff <(ls /home/alice) <(ls /home/bob)
History
Why does this post require moderator attention?
You might want to add some details to your flag.

1 comment thread

NB: I'm not marking "works for me" to encourage other folks to post better answers (if they want). Fo... (2 comments)
NB: I'm not marking "works for me" to encourage other folks to post better answers (if they want). Fo...
matthewsnyder‭ wrote 11 months ago

NB: I'm not marking "works for me" to encourage other folks to post better answers (if they want). For example, I've only addressed Bash, which is honestly a pretty bad choice of shell in this day and age.

Also, it technically doesn't work for me, because I use fish. :) I have no idea what the syntax for fish is, nor do I care, because I avoid this syntax like the plague.

jimbobmcgee‭ wrote 11 months ago

I have no idea what the syntax for fish

If memory serves, (command | psub) but, ironically, I think it just creates temp files under the hood...