1

I want to display a menu in linux bash using whiptail
When a menu item contains one or more dashes, whiptail fails to show the menu.
Example with only one item:

MQTT_PublisherArgs='-h {host} -t {topic} -m "{{message}}"'
whiptail --title "MQTT Configuration" --menu "" 0 70 0 "Publisher Arguments" "$MQTT_PublisherArgs"

When I replace the dashes with another character e.g. underscore, the menu is shown correctly.
I tried to escape the dashes with \- but the backslash is shown in the menu.

How can I display the menu item -h {host} -t {topic} -m "{{message}}"

When the user selects this item he will prompted to enter his proper arguments

SBF
  • 1,252
  • 3
  • 12
  • 21

1 Answers1

2

Replace

"$MQTT_PublisherArgs"

with

-- "$MQTT_PublisherArgs"

to tell whiptail that the following are not options.

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

Cyrus
  • 84,225
  • 14
  • 89
  • 153
  • As I read it, doesn't the OP have *several different* arguments in that string variable? As such, I'm not confident that the Right Thing is anything short of replacing it with an array. – Charles Duffy Nov 15 '19 at 21:33