fork download
  1. #!/bin/bash
  2. set -x
  3.  
  4. exec {myfunc_stdout_fd}>&1
  5. myfunc() {
  6. echo "Content sent to stdout as defined at invocation time"
  7. echo "Content sent to original stdout" >&"$myfunc_stdout_fd";
  8. }
  9.  
  10. myfunc_out=$(myfunc)
  11.  
  12. declare -p myfunc_out
Success #stdin #stdout #stderr 0s 19632KB
stdin
Standard input is empty
stdout
Content sent to original stdout
declare -- myfunc_out="Content sent to stdout as defined at invocation time"
stderr
+ exec
++ myfunc
++ echo 'Content sent to stdout as defined at invocation time'
++ echo 'Content sent to original stdout'
+ myfunc_out='Content sent to stdout as defined at invocation time'
+ declare -p myfunc_out