fork download
  1. #!/bin/bash
  2.  
  3. cd $(mktemp -d) # just for ideone, so we'll have write permissions
  4.  
  5. function my_function() {
  6. echo "result 1"
  7. echo "result 2" >&3
  8. echo "result 3" >&4
  9. }
  10.  
  11. my_function 3>foo.txt
  12. # the stdout is left untouched and will be printed.
  13. # the channel 3 is redirected to a file, and 4 is ignored
  14.  
  15. echo "----"
  16.  
  17. cat foo.txt
Success #stdin #stdout #stderr 0.01s 5472KB
stdin
Standard input is empty
stdout
result 1
----
result 2
stderr
./prog.sh: line 8: 4: Bad file descriptor