Reputation: 813
Suppose I have a shell command foo
that expects a file such as bar.txt
as an argument, and I want to pass a one-line file to foo
and then erase it like so:
echo "This is a one line file" > bar.txt
foo bar.txt
rm bar.txt
Is there a way to do this all in a single line of shell script without ever creating the file bar.txt
?
Upvotes: 1
Views: 414
Reputation: 3603
try command substitution like this
cat $(ls)
where, result of 'ls' will be substituted as an argument for 'cat' to execute
Upvotes: 0
Reputation: 55469
I'm assuming that foo doesn't try to read stdin. If so, as an alternative to the Process Substitution suggested by Cyrus, you can also do
echo "This is a one line file" | foo /dev/stdin
Upvotes: 0
Reputation: 88543
You can use Process Substitution:
foo <(echo "This is a one line file")
Upvotes: 3