Reputation: 573
I found out about Dialogs, so I'm updating menus today. So far, so good.
I came to one where I need to collect a user's input.
I have
dialog --title " INPUT FILE NAME: " --inputbox "$(ls)" 30 40 2> answer
This will send the users input to a file named "answer"
I have tried
dialog --title " INPUT FILE NAME: " --inputbox "$(ls)" 30 40 2> $answer
but that doesnt seem to do anything.
I tried
answer=$(dialog --title " INPUT FILE NAME: " --inputbox "$(ls)" 30 40 2)
but there is some kind of error.
Upvotes: 0
Views: 70
Reputation: 54495
The manual page (for dialog) tells the story:
Some widgets, e.g., checklist, will write text to dialog's output. Normally that is the standard error, but there are options for changing this: "
--output-fd
", "--stderr
" and "--stdout
". No text is written if the Cancel button (or ESC) is pressed; dialog exits immediately in that.
The reason dialog uses the standard error by default for its output is that it uses the curses/ncurses library, which normally prints its output (for the screen updates) to the standard output. To change dialog's behavior (and write to the standard output), use the "--stdout
" option.
Interestingly (though it may appear an obvious problem to solve because it complicates scripting), the Xdialog program implemented this option first; it seemed a Good Thing to add to dialog (see changelog).
Upvotes: 1
Reputation: 573
Done
dialog --title " INPUT FILE NAME: " --inputbox "$(ls )" 30 40 2>answer
ans=$(cat answer)
rm answer
Upvotes: 0