0

By default if we run

foo(){
  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:

foo(){
  mkfifo bar
  exec 1<>bar
  echo "myfoo"  # this gets written to the bar named pipe?
}

so we "repoint" stdout somewhere else perhaps?

1 Answers1

0

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.