Title: Running Dialog inside a loop
Tags: linux;bash;shell;loops;dialog
Question: I have this simple shell script and in it I am using Dialog the Linux program to make a dynamic graphical menu for a basic switch-case structure. I launch the program with the following parameters:
CHOICE=$(dialog --clear \
--backtitle "$BACKTITLE" \
--title "$TITLE" \
--menu "$MENU" \
$HEIGHT $WIDTH $CHOICE_HEIGHT \
"${OPTIONS[@]}" \
2&gt;&amp;1 &gt;/dev/tty)
The Dialog will exit once I have chosen any of the options of my switch-structure. I would like to run it inside a loop in a way that it would only exit if I press the cancel-button. If I put the whole script inside one while true-loop then it won't exit once I select Cancel.
How can I make a loop that can be exited by selecting Cancel? What is the most meaningful way to go on about this? Does Cancel return some value that I can use as a parameter for the loop so it can be broken?

Here is the accepted answer: from man dialog
No text is written if the Cancel button (or ESC) is pressed; dialog  exits  immediately
yes you can do a loop in your case , and you will test for emptyness .
a example
CHOICE="foobar" ;
while [ -n  "$CHOICE"  ] ;
CHOICE=$(dialog --clear \
--backtitle "$BACKTITLE" \
--title "$TITLE" \
--menu "$MENU" \
$HEIGHT $WIDTH $CHOICE_HEIGHT \
"${OPTIONS[@]}" \
2&gt;&amp;1 &gt;/dev/tty)
if [ -n "$CHOICE" ]
then
reset
echo "${CHOICE}"
sleep 5
Comment for this answer: Maybe `echo "${CHOICE}"`?


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2019:00:11/17/19', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<linux><bash><shell><loops><dialog>', 'Title': 'Running Dialog inside a loop', 'ViewCount': 454, 'id': 58905412, 'user_AboutMe': '', 'user_AccountId': 11715599.0, 'user_DisplayName': 'WaitoPiggu', 'user_Reputation': 71.0, 'user_Views': 18.0, 'user_id': 8576219.0}}