pipe both, stdout and stderr in the fish shell

Anton Harald picture Anton Harald · May 30, 2016 · Viewed 19.5k times · Source

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

Answer

glenn jackman picture glenn jackman · May 30, 2016

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/index.html#redirects