I'm working on a simple bash script menu, and I've followed this guide to get started.
It works fine, but I don't really like how stderr is redirected to a file and then used in the main loop.
In my script I have a few functions that draw different things. I'm trying to modify them to work without having to write to the files. One of the functions to draw a menu looks like th is (simplified):
function render_menu()
{
dialog --clear --backtitle "$backtitle" --title "Some Title" --menu "My fancy menu" 50 15 4 "one" "option 1" "two" "option 2"
echo $?
}
And it is called from the main loop like:
while true; do
selection="$(render_menu)"
case $selection in
Quit) break;;
Back) #some logic;;
*) #some logic;;
esac
done
But it doesn't work, when I run the script I don't see the menu. I assume because the output of dialog has been redirected?
The way I want it to work is that the dialog is displayed, and the output from it is stored in the variable selection. Is that possible without the need for an external file? If not, why so?
Selectionwill contain the return code and the entire contents of dialog.