By default if we run

  echo "myfoo"

it will go to stdout. My question is, for a bash script or function, is there a programmatic way to change the device so that commands don't automatically write to stdout?

maybe something like this:

  mkfifo bar
  exec 1<>bar
  echo "myfoo"  # this gets written to the bar named pipe?

so we "repoint" stdout somewhere else perhaps?


1 Answer 1


This technique will probably do the trick: Using process substitution, only send stderr to process

Basically, you call:

exec > $some_file

using process substitution, you can do something like:

exec > >( while read line; do echo " stdout: $line"; done )

that means that all stdout will go to that file instead of to the terminal.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.