-1

I try to run the following command (ref.) using nohup, which basically separates stdout and stderr into two processes.

{ foo 2>&1 1>&3 3>&- | sed -u 's/^/err: /'; } 3>&1 1>&2 | sed -u 's/^/out: /'

The foo script is like below.

#!/bin/bash
while true; do
   echo a
   echo b >&2
   sleep 1
done

This is the test result.

$ nohup { foo 2>&1 1>&3 3>&- | sed -u 's/^/err: /'; } 3>&1 1>&2 | sed -u 's/^/out: /' >/dev/null 2>&1 &
-bash: syntax error near unexpected token `}'
user180574
  • 5,681
  • 13
  • 53
  • 94

1 Answers1

1

That's syntatically impossible. But you can wrap your {} in a sh -c cmd:

nohup sh -c 'foo 2>&1 1>&3 3>&- | sed -u "s/^/err: /"'

Notice I change the single quote for sed to double quote.

DannyNiu
  • 1,313
  • 8
  • 27