Xdialog Capture Comments


The Xdialog below ask for a name.

$ Xdialog --inputbox "Please enter your name:" 20 60
Byron

Note that the input from the Xdialog is printed on the terminal. Now let's try to capture that information into a file.

$ Xdialog --inputbox "Please enter your name:" 20 60 > myname
Byron

$ cat myname
$ 
Oops?! Note that the input from the Xdialog is STILL printed on the terminal, and the file is empty. Why? Because by default Xdialog writes to the standard error file. Solution: use the --stdout option for Xdialog.

$ Xdialog --stdout --inputbox "Please enter your name:" 20 60 > myname
$ cat myname
Byron
$ 
This is better. However it creates unnecessary files. We need to be able to transfer directly into a variable. The command substitution notation: $(cmd) along with assignment solves the problem.

$ name=$(Xdialog --stdout --inputbox "Please enter your name:" 20 60)
$ echo $name
Byron