将 whiptail 与包含破折号('-')的变量一起使用
Using whiptail with variable containing dash ('-')
我想在 linux bash 中使用 whiptail
显示菜单
当菜单项包含一个或多个破折号时,whiptail 无法显示菜单。
只有一项的示例:
MQTT_PublisherArgs='-h {host} -t {topic} -m "{{message}}"'
whiptail --title "MQTT Configuration" --menu "" 0 70 0 "Publisher Arguments" "$MQTT_PublisherArgs"
当我用另一个字符替换破折号时,例如下划线,菜单显示正确。
我试图用 \-
转义破折号,但反斜杠显示在菜单中。
如何显示菜单项-h {host} -t {topic} -m "{{message}}"
当用户选择此项时,他会提示输入正确的参数
替换
"$MQTT_PublisherArgs"
和
-- "$MQTT_PublisherArgs"
告诉whiptail
以下不是选项。
来自man whiptail
:
whiptail interprets arguments starting with a dash "-" as being arguments. To avoid this,
and start some text in, for example, a menubox item, with a dash, whiptail honours the getopt
convention of accepting the special argument "--" which means that all following arguments
with dashes are to be treated verbatim and not parsed as options.
我想在 linux bash 中使用 whiptail
显示菜单
当菜单项包含一个或多个破折号时,whiptail 无法显示菜单。
只有一项的示例:
MQTT_PublisherArgs='-h {host} -t {topic} -m "{{message}}"'
whiptail --title "MQTT Configuration" --menu "" 0 70 0 "Publisher Arguments" "$MQTT_PublisherArgs"
当我用另一个字符替换破折号时,例如下划线,菜单显示正确。
我试图用 \-
转义破折号,但反斜杠显示在菜单中。
如何显示菜单项-h {host} -t {topic} -m "{{message}}"
当用户选择此项时,他会提示输入正确的参数
替换
"$MQTT_PublisherArgs"
和
-- "$MQTT_PublisherArgs"
告诉whiptail
以下不是选项。
来自man whiptail
:
whiptail interprets arguments starting with a dash "-" as being arguments. To avoid this, and start some text in, for example, a menubox item, with a dash, whiptail honours the getopt convention of accepting the special argument "--" which means that all following arguments with dashes are to be treated verbatim and not parsed as options.