Also, note that the interpretation of $? as to "Whether Cancel was chosen"
can be the other way around:
When 'Cancel' was chosen, only then is $? -eq 1
and on the other hand, when a proper menu choice
was chosen, $? is 0 (and the choice itself is in another variable
that you define yourself).
Example code:
exec 3>&1
result=$(dialog --title "Choose action from menu" \
--menu "\n Use arrows - UP/DOWN \n\
Press [Enter] to select\n" 20 40 10 \
"I" "Installation" \
"S" "Check system" \
"X" "eXit" 2>&1 1>&3);
Now the dialog by default also shows a OK and Cancel buttons.
If user has chosen "OK", then $? = 0, and $result = 'I' or 'S' or 'X'
If user has chosen "Cancel", $? = 1, and the $result was undefined ('')
My 'dialog --version' is 1.3-20160209