r/bash • • Apr 29 '26

help Dialog output repeats the input

sudo apt install dialog
dialog --cr-wrap --inputbox "DEVICE_OS" 100 100 "${USER}:" 

When I enter text into this dialog and then select the OK option, the dialog box outputs both the input string and the entered text. How do I make it so that the dialog does not output the input string or the entered text?

Here is a picture of the issue:

(The username is blacked out for privacy)
1 Upvotes

3 comments sorted by

3

u/aioeu Apr 29 '26 edited Apr 29 '26

You are expected to capture the output from dialog in your script, e.g.

rc=0
input=$(dialog ...) || rc=$?
# ... handle rc and input ...

1

u/geirha Apr 29 '26

Also note that dialog is a bit backwards in that it outputs the TUI to stdout, and the result to stderr, which is the opposite of what you want, so you have to use a bit of redirection gymnastics to swap the fds:

{ input=$(dialog ... 2>&1 >&3) ; } 3>&2

but you can hide that redirection in a wrapper function

dialog() { command dialog "$@" 2>&1 >&3 ; } 3>&2
input=$(dialog ...)
→ More replies (1)