Bash对话框取消按钮返回,退出代码为0;逃生钥匙也是如此

Bash对话框取消按钮返回,退出代码为0;逃生钥匙也是如此,bash,dialog,Bash,Dialog,我创建了一个简单的菜单对话框,但是取消按钮和退出键返回0作为退出代码。我做错了什么 exec 3>&1; selection=$(dialog \ --title "Main Menu" \ --backtitle "$BACK_TITLE" \ --menu "Choose an option to configure. Up and down arrows change selection. Use the Enter key to make a sel

我创建了一个简单的菜单对话框,但是取消按钮和退出键返回0作为退出代码。我做错了什么

exec 3>&1;
selection=$(dialog \
    --title "Main Menu" \
    --backtitle "$BACK_TITLE" \
    --menu "Choose an option to configure. Up and down arrows change selection. Use the Enter key to make a selection." "$HEIGHT" "$WIDTH" 5 \
    0 "Select Directory" \
    1 "Select File Extension" \
    2 "Options" \
    3 "Execute with current config" \
    4 "Exit" \
    2>&1 1>&3);
exec 3>&-;
exitStatus=$?
echo "selected: $selection exit code: $exitStatus"
当我按escape键或cancel(取消)按钮时,会出现上述情况


选中:退出代码:0

您正在保存上一个
exec
命令的退出状态,而不是
对话框的退出状态。将
exitStatus=$?
放在
selection=…
之后

exec 3>&1;
selection=$(dialog \
    --title "Main Menu" \
    --backtitle "$BACK_TITLE" \
    --menu "Choose an option to configure. Up and down arrows change selection. Use the Enter key to make a selection." "$HEIGHT" "$WIDTH" 5 \
    0 "Select Directory" \
    1 "Select File Extension" \
    2 "Options" \
    3 "Execute with current config" \
    4 "Exit" \
    2>&1 1>&3);
exitStatus=$?
exec 3>&-;
echo "selected: $selection exit code: $exitStatus"
exec 3>&1;
选择=$(对话框)\
--标题“主菜单”\
--backtitle“$BACK\u TITLE”\
--菜单“选择要配置的选项。上下箭头更改选择。使用Enter键进行选择。”“$HEIGHT”“$WIDTH”5\
0“选择目录”\
1“选择文件扩展名”\
2“选项”\
3“使用当前配置执行”\
4“出口”\
2>&1 1>&3);
exitStatus=$?
执行官3>&;

echo“selected:$selection exit code:$exitStatus”
Ah crap!我知道这是件愚蠢的事。我不想承认我想弄明白这件事已经有多久了。非常感谢!