So let's say there's a command called "foo" and it requires 2 .txt files, however I would like to run the "foo" command without having to create 2 .txt files everytime I want to run it, then delete the 2 .txt files.
E.g:
foo --param1=$(curl www.repository-param1-latest.com) --param2=$(curl www.repository-param2-latest.com)
So in the scenario above, I've got a website with the different versions of params stored there, and would simply like to curl them. However "foo" only accepts a file, so if I try and do the above, it will give me an error saying invalid file name. How can I do something like the above, without having to create a file, then delete it, I'm fine with it doing it automatically.
Has to be valid for both mac and linux, and being able to do it without needing sudo or root access as well.
CodePudding user response:
If your shell supports process substitution, you might try
foo --param1=<(curl ...) --param2=<(curl ...)
Or, you can write a function to download the files and later remove them. This way, you can parameterize the calls to curl:
myfoo () {
curl -o /tmp/out1.$$ "www.$1-..."
curl -o /tmp/out2.$$ "www.$2-..."
foo --param1=/tmp/out1.$$ --param2=/tmp/out2.$$
rm /tmp/out[12].$$
}