Skip to main content
Became Hot Network Question
added 14 characters in body
Source Link
finefoot
  • 3.6k
  • 4
  • 30
  • 58
mkfifo foo printf %s\\n bar | tee foo & tr -s '[:lower:]' '[:upper:]' <foo wait rm foo 

This is a working POSIX shell script of what I want to do:

  • printf %s\\n bar is symbolic for an external program producing stdout
  • tr -s '[:lower:]' '[:upper:]' is symbolic for another command that is supposed to receive the stdout and do something with it
  • tee duplicates stdout to named pipe foo

And the output is as expected:

bar BAR 

Now I'd like to tidy up the code so it becomes external_program | my_function. Something like this:

f() ( mkfifo foo tee foo & tr -s '[:lower:]' '[:upper:]' <foo wait rm foo ) printf %s\\n bar | f 

But now there is no output at all.

mkfifo foo printf %s\\n bar | tee foo & tr -s '[:lower:]' '[:upper:]' <foo rm foo 

This is a working POSIX shell script of what I want to do:

  • printf %s\\n bar is symbolic for an external program producing stdout
  • tr -s '[:lower:]' '[:upper:]' is symbolic for another command that is supposed to receive the stdout and do something with it
  • tee duplicates stdout to named pipe foo

And the output is as expected:

bar BAR 

Now I'd like to tidy up the code so it becomes external_program | my_function. Something like this:

f() ( mkfifo foo tee foo & tr -s '[:lower:]' '[:upper:]' <foo rm foo ) printf %s\\n bar | f 

But now there is no output at all.

mkfifo foo printf %s\\n bar | tee foo & tr -s '[:lower:]' '[:upper:]' <foo wait rm foo 

This is a working POSIX shell script of what I want to do:

  • printf %s\\n bar is symbolic for an external program producing stdout
  • tr -s '[:lower:]' '[:upper:]' is symbolic for another command that is supposed to receive the stdout and do something with it
  • tee duplicates stdout to named pipe foo

And the output is as expected:

bar BAR 

Now I'd like to tidy up the code so it becomes external_program | my_function. Something like this:

f() ( mkfifo foo tee foo & tr -s '[:lower:]' '[:upper:]' <foo wait rm foo ) printf %s\\n bar | f 

But now there is no output at all.

Source Link
finefoot
  • 3.6k
  • 4
  • 30
  • 58

Duplicate stdout to pipe into another command with named pipe in POSIX shell script function

mkfifo foo printf %s\\n bar | tee foo & tr -s '[:lower:]' '[:upper:]' <foo rm foo 

This is a working POSIX shell script of what I want to do:

  • printf %s\\n bar is symbolic for an external program producing stdout
  • tr -s '[:lower:]' '[:upper:]' is symbolic for another command that is supposed to receive the stdout and do something with it
  • tee duplicates stdout to named pipe foo

And the output is as expected:

bar BAR 

Now I'd like to tidy up the code so it becomes external_program | my_function. Something like this:

f() ( mkfifo foo tee foo & tr -s '[:lower:]' '[:upper:]' <foo rm foo ) printf %s\\n bar | f 

But now there is no output at all.