DragonHawk

capturefd3numfd.sh

Jun 26th, 2012
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/sh
  2.  
  3. # Nothing up my sleeve...
  4. unset ANSWER
  5.  
  6. # dupe stdout (fd 1) to fd 4 (using redirection)
  7. # change the shell's idea of what stdout is to be fd 4 (exec)
  8. exec 4>&1
  9.  
  10. # set-up a command substitution
  11. # the command is a subshell expression, with redirection applied
  12. #   the redirection dupes stdout again, on to fd 3
  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 fd 3 we opened earlier
  16. ANSWER=$( ( dialog --output-fd 3 --inputbox 'Speak Friend and enter' 0 0  > /dev/fd/4 ) 3>&1 )
  17.  
  18. # Ta-da!
  19. echo ANSWER=\<$ANSWER\>
Advertisement
Add Comment
Please, Sign In to add comment