Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to disguise stdout as a file?

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Has to be valid for both mac and linux, and being able to do it without needing sudo or root access as well.

>Solution :

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].$$
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading