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. :(

  • 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 '18 at 20:55
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

  • Sadly it again gave me an error saying the file isn’t executable. :( – HappyFace Dec 16 '18 at 19:24
  • That's probably unrelated. What exactly did you run? – V13 Dec 16 '18 at 19:25
  • aria2c “some-url” —on-download-complete <(echo “touch nnn6”) and the — is typed wrongly on my iPad. – HappyFace Dec 16 '18 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 '18 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 '18 at 20:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.