bash 如何配置对话框bash的取消按钮?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27155286/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 11:53:01  来源:igfitidea点击:

how can i configure the cancel button of dialog box bash?

bashshell

提问by Fimo

for example i would like to configure the cancel button of this dialog box.

例如我想配置这个对话框的取消按钮。

dialog --backtitle "Dialog - Form sample" \
 --form " Form Test - use [up] [down] to select input field " 21 70 18 \
 "Network-ID:" 2 2 "" 2 15 20 0\
 "Subnet Mask:" 4 2 "" 4 15 20 0\

how can i do this ?

我怎样才能做到这一点 ?

回答by Jukka Paulin

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).

When 'Cancel' was chosen, only then is $? -eq 1 and on the other hand, when a proper menu choice was chosen, $? 是 0(并且选择本身在您自己定义的另一个变量中)。

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 ('')

如果用户选择了“OK”,那么 $? = 0, and $result = 'I' or 'S' or 'X' 如果用户选择了“取消”,$? = 1,并且 $result 未定义 ('')

My 'dialog --version' is 1.3-20160209

我的“对话框 --version”是 1.3-20160209