View difference between Paste ID: XdxWjpeU and RGBuRw0e
SHOW: | | - or go back to the newest paste.
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)
6+
# dupe stdout (fd 1) to fd 4 (using redirection)
7-
# change the shell's idea of what stdout is to be TERM_OUT (exec)
7+
# change the shell's idea of what stdout is to be fd 4 (exec)
8-
exec {TERM_OUT}>&1
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, calling the new fd $OOB here
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 $OOB fd we opened earlier
15+
#   and we tell dialog to send its results to the fd 3 we opened earlier
16-
# OOB = out-of-band
16+
ANSWER=$( ( dialog --output-fd 3 --inputbox 'Speak Friend and enter' 0 0  > /dev/fd/4 ) 3>&1 )
17-
ANSWER=$( ( dialog --output-fd $OOB --inputbox 'Speak Friend and enter' 0 0  > /dev/fd/$TERM_OUT ) {OOB}>&1 )
17+
18
# Ta-da!
19
echo ANSWER=\<$ANSWER\>