Shell: Is it possible to give a string as a file to a command?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












1














Suppose we have a command,



eval-some-language —-path=<filename>


And we want to do something like this:



eval-some-language —-path=“say hello world!
exit 3”


I think the following solution might work for one file, and if stdin is not used for sth else:



eval-some-language —-path=“/dev/stdin” <<<“say hello ...”


Does this work with all commands? How portable is it? (macOS?)



And is there any other ways to do this?



Update: Both my solution, the accepted answer, and zsh’s =() don’t work if the file needs to be executable. :(










share|improve this question



















  • 1




    This is an XY problem. Why not ask what you want to accomplish? What do you want to do to each download?
    – Dani_l
    Dec 16 at 20:55















1














Suppose we have a command,



eval-some-language —-path=<filename>


And we want to do something like this:



eval-some-language —-path=“say hello world!
exit 3”


I think the following solution might work for one file, and if stdin is not used for sth else:



eval-some-language —-path=“/dev/stdin” <<<“say hello ...”


Does this work with all commands? How portable is it? (macOS?)



And is there any other ways to do this?



Update: Both my solution, the accepted answer, and zsh’s =() don’t work if the file needs to be executable. :(










share|improve this question



















  • 1




    This is an XY problem. Why not ask what you want to accomplish? What do you want to do to each download?
    – Dani_l
    Dec 16 at 20:55













1












1








1







Suppose we have a command,



eval-some-language —-path=<filename>


And we want to do something like this:



eval-some-language —-path=“say hello world!
exit 3”


I think the following solution might work for one file, and if stdin is not used for sth else:



eval-some-language —-path=“/dev/stdin” <<<“say hello ...”


Does this work with all commands? How portable is it? (macOS?)



And is there any other ways to do this?



Update: Both my solution, the accepted answer, and zsh’s =() don’t work if the file needs to be executable. :(










share|improve this question















Suppose we have a command,



eval-some-language —-path=<filename>


And we want to do something like this:



eval-some-language —-path=“say hello world!
exit 3”


I think the following solution might work for one file, and if stdin is not used for sth else:



eval-some-language —-path=“/dev/stdin” <<<“say hello ...”


Does this work with all commands? How portable is it? (macOS?)



And is there any other ways to do this?



Update: Both my solution, the accepted answer, and zsh’s =() don’t work if the file needs to be executable. :(







linux bash filesystems zsh command-substitution






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 16 at 19:46

























asked Dec 16 at 19:09









HappyFace

31811




31811







  • 1




    This is an XY problem. Why not ask what you want to accomplish? What do you want to do to each download?
    – Dani_l
    Dec 16 at 20:55












  • 1




    This is an XY problem. Why not ask what you want to accomplish? What do you want to do to each download?
    – Dani_l
    Dec 16 at 20:55







1




1




This is an XY problem. Why not ask what you want to accomplish? What do you want to do to each download?
– Dani_l
Dec 16 at 20:55




This is an XY problem. Why not ask what you want to accomplish? What do you want to do to each download?
– Dani_l
Dec 16 at 20:55










1 Answer
1






active

oldest

votes


















1














Try this:



eval-some-language --path=<(echo "hello world")


<() will generate a file descriptor, tied to the output of the command and pass it as /dev/fd/xxx. E.g:



$ echo <(echo aaa)
/dev/fd/63

$ echo <(echo test) <(echo second test)
/dev/fd/63 /dev/fd/62


For slightly more information see the "Process Substittution" section in man bash






share|improve this answer




















  • Sadly it again gave me an error saying the file isn’t executable. :(
    – HappyFace
    Dec 16 at 19:24










  • That's probably unrelated. What exactly did you run?
    – V13
    Dec 16 at 19:25










  • aria2c “some-url” —on-download-complete <(echo “touch nnn6”) and the — is typed wrongly on my iPad.
    – HappyFace
    Dec 16 at 19:28






  • 1




    --on-download-complete requires an executable script to execute. That's way different than just a file and certainly doesn't work with your solution either. You need an actual file if you want to execute it. Your best solution is to generate a temporary file with mktemp, make it executable and pass that as a parameter.
    – V13
    Dec 16 at 19:41






  • 1




    @jimmij, they seem to want an executable file that their program executes once it downloads something. I don't think that can ever be possible because executing a program with execve() will require a real file with executable permissions.
    – V13
    Dec 16 at 20:02










Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f489362%2fshell-is-it-possible-to-give-a-string-as-a-file-to-a-command%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














Try this:



eval-some-language --path=<(echo "hello world")


<() will generate a file descriptor, tied to the output of the command and pass it as /dev/fd/xxx. E.g:



$ echo <(echo aaa)
/dev/fd/63

$ echo <(echo test) <(echo second test)
/dev/fd/63 /dev/fd/62


For slightly more information see the "Process Substittution" section in man bash






share|improve this answer




















  • Sadly it again gave me an error saying the file isn’t executable. :(
    – HappyFace
    Dec 16 at 19:24










  • That's probably unrelated. What exactly did you run?
    – V13
    Dec 16 at 19:25










  • aria2c “some-url” —on-download-complete <(echo “touch nnn6”) and the — is typed wrongly on my iPad.
    – HappyFace
    Dec 16 at 19:28






  • 1




    --on-download-complete requires an executable script to execute. That's way different than just a file and certainly doesn't work with your solution either. You need an actual file if you want to execute it. Your best solution is to generate a temporary file with mktemp, make it executable and pass that as a parameter.
    – V13
    Dec 16 at 19:41






  • 1




    @jimmij, they seem to want an executable file that their program executes once it downloads something. I don't think that can ever be possible because executing a program with execve() will require a real file with executable permissions.
    – V13
    Dec 16 at 20:02















1














Try this:



eval-some-language --path=<(echo "hello world")


<() will generate a file descriptor, tied to the output of the command and pass it as /dev/fd/xxx. E.g:



$ echo <(echo aaa)
/dev/fd/63

$ echo <(echo test) <(echo second test)
/dev/fd/63 /dev/fd/62


For slightly more information see the "Process Substittution" section in man bash






share|improve this answer




















  • Sadly it again gave me an error saying the file isn’t executable. :(
    – HappyFace
    Dec 16 at 19:24










  • That's probably unrelated. What exactly did you run?
    – V13
    Dec 16 at 19:25










  • aria2c “some-url” —on-download-complete <(echo “touch nnn6”) and the — is typed wrongly on my iPad.
    – HappyFace
    Dec 16 at 19:28






  • 1




    --on-download-complete requires an executable script to execute. That's way different than just a file and certainly doesn't work with your solution either. You need an actual file if you want to execute it. Your best solution is to generate a temporary file with mktemp, make it executable and pass that as a parameter.
    – V13
    Dec 16 at 19:41






  • 1




    @jimmij, they seem to want an executable file that their program executes once it downloads something. I don't think that can ever be possible because executing a program with execve() will require a real file with executable permissions.
    – V13
    Dec 16 at 20:02













1












1








1






Try this:



eval-some-language --path=<(echo "hello world")


<() will generate a file descriptor, tied to the output of the command and pass it as /dev/fd/xxx. E.g:



$ echo <(echo aaa)
/dev/fd/63

$ echo <(echo test) <(echo second test)
/dev/fd/63 /dev/fd/62


For slightly more information see the "Process Substittution" section in man bash






share|improve this answer












Try this:



eval-some-language --path=<(echo "hello world")


<() will generate a file descriptor, tied to the output of the command and pass it as /dev/fd/xxx. E.g:



$ echo <(echo aaa)
/dev/fd/63

$ echo <(echo test) <(echo second test)
/dev/fd/63 /dev/fd/62


For slightly more information see the "Process Substittution" section in man bash







share|improve this answer












share|improve this answer



share|improve this answer










answered Dec 16 at 19:21









V13

2,799613




2,799613











  • Sadly it again gave me an error saying the file isn’t executable. :(
    – HappyFace
    Dec 16 at 19:24










  • That's probably unrelated. What exactly did you run?
    – V13
    Dec 16 at 19:25










  • aria2c “some-url” —on-download-complete <(echo “touch nnn6”) and the — is typed wrongly on my iPad.
    – HappyFace
    Dec 16 at 19:28






  • 1




    --on-download-complete requires an executable script to execute. That's way different than just a file and certainly doesn't work with your solution either. You need an actual file if you want to execute it. Your best solution is to generate a temporary file with mktemp, make it executable and pass that as a parameter.
    – V13
    Dec 16 at 19:41






  • 1




    @jimmij, they seem to want an executable file that their program executes once it downloads something. I don't think that can ever be possible because executing a program with execve() will require a real file with executable permissions.
    – V13
    Dec 16 at 20:02
















  • Sadly it again gave me an error saying the file isn’t executable. :(
    – HappyFace
    Dec 16 at 19:24










  • That's probably unrelated. What exactly did you run?
    – V13
    Dec 16 at 19:25










  • aria2c “some-url” —on-download-complete <(echo “touch nnn6”) and the — is typed wrongly on my iPad.
    – HappyFace
    Dec 16 at 19:28






  • 1




    --on-download-complete requires an executable script to execute. That's way different than just a file and certainly doesn't work with your solution either. You need an actual file if you want to execute it. Your best solution is to generate a temporary file with mktemp, make it executable and pass that as a parameter.
    – V13
    Dec 16 at 19:41






  • 1




    @jimmij, they seem to want an executable file that their program executes once it downloads something. I don't think that can ever be possible because executing a program with execve() will require a real file with executable permissions.
    – V13
    Dec 16 at 20:02















Sadly it again gave me an error saying the file isn’t executable. :(
– HappyFace
Dec 16 at 19:24




Sadly it again gave me an error saying the file isn’t executable. :(
– HappyFace
Dec 16 at 19:24












That's probably unrelated. What exactly did you run?
– V13
Dec 16 at 19:25




That's probably unrelated. What exactly did you run?
– V13
Dec 16 at 19:25












aria2c “some-url” —on-download-complete <(echo “touch nnn6”) and the — is typed wrongly on my iPad.
– HappyFace
Dec 16 at 19:28




aria2c “some-url” —on-download-complete <(echo “touch nnn6”) and the — is typed wrongly on my iPad.
– HappyFace
Dec 16 at 19:28




1




1




--on-download-complete requires an executable script to execute. That's way different than just a file and certainly doesn't work with your solution either. You need an actual file if you want to execute it. Your best solution is to generate a temporary file with mktemp, make it executable and pass that as a parameter.
– V13
Dec 16 at 19:41




--on-download-complete requires an executable script to execute. That's way different than just a file and certainly doesn't work with your solution either. You need an actual file if you want to execute it. Your best solution is to generate a temporary file with mktemp, make it executable and pass that as a parameter.
– V13
Dec 16 at 19:41




1




1




@jimmij, they seem to want an executable file that their program executes once it downloads something. I don't think that can ever be possible because executing a program with execve() will require a real file with executable permissions.
– V13
Dec 16 at 20:02




@jimmij, they seem to want an executable file that their program executes once it downloads something. I don't think that can ever be possible because executing a program with execve() will require a real file with executable permissions.
– V13
Dec 16 at 20:02

















draft saved

draft discarded
















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f489362%2fshell-is-it-possible-to-give-a-string-as-a-file-to-a-command%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown






Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay