You can use the following redirections:
3>&1 text=$(dialog --backtitle 'foo' --title 'bar' --clear --inputbox 'baz' 0 0 2>&1 >&3>/dev/tty) case $? in 0) echo "Approved with: $text" ;; 1) echo "Canceled by the cancel button" ;; 255|*) echo "Canceled by the escape key" ;; esac Here's what's going on:
- Dup fd 1 to fd 3 to preserve the original stdout (
/dev/tty) - fd 1 gets connected to a pipe by the command substitution construct
- Dup fd 1 to fd 2 (
dialog's stderr is connected to the pipe) - Dup fd 3 to fd 1 (
dialog's stdout is connected to the original stdout)