pipe both, stdout and stderr in the fish shell

Fish

Fish Problem Overview


I know this has been an issue for a while and I found a lot of discussion about it, however I didn't get which would be finally a way to get it done: pipe both, stdout and stderr. In bash, this would be simply:

cmd 2>&1 | cmd2

Fish Solutions


Solution 1 - Fish

That syntax works in fish too. A demo:

$ function cmd1
      echo "this is stdout"
      echo "this is stderr" >&2
  end

$ function cmd2
      rev
  end

$ cmd1 | cmd2
this is stderr
tuodts si siht

$ cmd1 &| cmd2
rredts si siht
tuodts si siht

Docs: https://fishshell.com/docs/current/language.html#redirects

Solution 2 - Fish

There's also a handy shortcut, per these docs

&>

Here's the relevant quote (emphasis and white space, mine):

> As a convenience, the redirection &> can be used to direct both stdout > and stderr to the same destination. For example: > > echo hello &> all_output.txt > redirects both stdout and stderr to the file > all_output.txt. This is equivalent to echo hello > all_output.txt > 2>&1.

Categories

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAnton HaraldView Question on Stackoverflow
Solution 1 - Fishglenn jackmanView Answer on Stackoverflow
Solution 2 - FishNavelgazerView Answer on Stackoverflow