Suppose I wanted to manipulate multiple output streams of a command, without changing or combining what output is sent to which stream. This is ideal for modularity, so that a convenience filter (or whatever) doesn't preclude other, later uses.
Creating an example stuff script that writes to stdout and stderr:
#!/bin/bash
echo "One"
echo "Two" 1>&2
I could fiddle with stdout via a pipe:
./stuff | sed 's/One/1/g'
# Stdout: 1
# Stderr: Two
To simultaneously fiddle with stderr, I wrap everything in a block and use 2>|:
begin; ./stuff | sed 's/One/1/g'; end 2>| sed 's/Two/2/g' 1>&2
# Stdout: 1
# Stderr: 2
Success! Both streams were processed, without losing out/err information.
I think the closest analogue in Bash is the following:
./stuff 1> >(sed 's/One/1/g') 2> >(sed 's/Two/2/g' 1>&2)
# Stdout: 1
# Stderr: 2
This is bit more terse, but inferior to the fish example as the shell returns early.
I have two questions:
- Is my fish example correct & reasonable?
- Is there a better way to do multiple redirection in fish that I should be aware of?
Thanks! 😎
Suppose I wanted to manipulate multiple output streams of a command, without changing or combining what output is sent to which stream. This is ideal for modularity, so that a convenience filter (or whatever) doesn't preclude other, later uses.
Creating an example
stuffscript that writes to stdout and stderr:I could fiddle with stdout via a pipe:
To simultaneously fiddle with stderr, I wrap everything in a block and use
2>|:Success! Both streams were processed, without losing out/err information.
I think the closest analogue in Bash is the following:
This is bit more terse, but inferior to the fish example as the shell returns early.
I have two questions:
Thanks! 😎