组合表单和按钮时如何在 YAD 中获取值 // 用户指定按钮的退出代码
How to get values in YAD when combining form and button // Exit codes for user-specified buttons
#!/bin/bash
array=$(yad \
--separator="\n" \
--form \
--field="Number":NUM 1 \
--field="Text":TEXT \
--button="b1:1" \
--button="b2:2" \
--button="b3:3" )
echo $?
echo "${array[@]}"
当按下b1或b3时,数组为空。为什么?如何修改它以始终获得数组中 NUM- 和 TEXT-form-field 的答案以及按钮编号为 $? ?
来自联机帮助页:
Exit codes for user-specified buttons must be specified in command line.
Even exit code mean to print result, odd just return exit code.
因此,您需要为按钮使用 even 退出代码
编辑:
我一直在寻找一种方法 稳健地 将 yad
的输出加载到 bash 数组中,但是 --separator
选项没有' 好像支持了null byte
。然而,有一个 --quoted-output
的 shell 可以与 eval
:
一起使用
quoted_input=$(
yad --quoted-output \
--separator=' ' \
--form \
--field='Number':NUM 1 \
--field='Text':TEXT \
--button='b1':10 \
--button='b2':20 \
--button='b3':30 \
echo $?
)
eval "array=( $quoted_input )"
[0x01-0x7f]
范围内没有字符破坏它,所以它应该是安全的,但使用它需要您自担风险。
#!/bin/bash
array=$(yad \
--separator="\n" \
--form \
--field="Number":NUM 1 \
--field="Text":TEXT \
--button="b1:1" \
--button="b2:2" \
--button="b3:3" )
echo $?
echo "${array[@]}"
当按下b1或b3时,数组为空。为什么?如何修改它以始终获得数组中 NUM- 和 TEXT-form-field 的答案以及按钮编号为 $? ?
来自联机帮助页:
Exit codes for user-specified buttons must be specified in command line.
Even exit code mean to print result, odd just return exit code.
因此,您需要为按钮使用 even 退出代码
编辑:
我一直在寻找一种方法 稳健地 将 yad
的输出加载到 bash 数组中,但是 --separator
选项没有' 好像支持了null byte
。然而,有一个 --quoted-output
的 shell 可以与 eval
:
quoted_input=$(
yad --quoted-output \
--separator=' ' \
--form \
--field='Number':NUM 1 \
--field='Text':TEXT \
--button='b1':10 \
--button='b2':20 \
--button='b3':30 \
echo $?
)
eval "array=( $quoted_input )"
[0x01-0x7f]
范围内没有字符破坏它,所以它应该是安全的,但使用它需要您自担风险。