DragonHawk

capturefd3.sh

Jun 25th, 2012
386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.73 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. # Nothing up my sleeve...
  4. unset ANSWER
  5.  
  6. # dupe stdout (fd 1) to a new fd, which we call TERM_OUT (redirection)
  7. # change the shell's idea of what stdout is to be TERM_OUT (exec)
  8. exec {TERM_OUT}>&1
  9.  
  10. # set-up a command substitution
  11. # the command is a subshell expression, with redirection applied
  12. #   the redirection dupes stdout again, calling the new fd $OOB here
  13. # the subshell itself invokves dialog(1)
  14. #   we apply redirection to this to put dialog's output back on the terminal
  15. #   and we tell dialog to send its results to the $OOB fd we opened earlier
  16. # OOB = out-of-band
  17. ANSWER=$( ( dialog --output-fd $OOB --inputbox 'Speak Friend and enter' 0 0  > /dev/fd/$TERM_OUT ) {OOB}>&1 )
  18.  
  19. # Ta-da!
  20. echo ANSWER=\<$ANSWER\>
Advertisement
Add Comment
Please, Sign In to add comment