Duplicate stdout to pipe into another command with named pipe in POSIX shell script function
5
votes
2
answers
294
views
mkfifo foo
printf %s\\n bar | tee foo &
tr -s '[:lower:]' '[:upper:]'
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:]'
But now there is no output at all.
Asked by finefoot
(3554 rep)
Mar 9, 2025, 01:34 PM
Last activity: Mar 9, 2025, 03:19 PM
Last activity: Mar 9, 2025, 03:19 PM