Search code examples
bashwhiptail

String starting with hyphen minus fails with whiptail


I have this simple script displaying msgbox using whiptail.

#!/bin/bash

str="-|foo\n"
whiptail --title "test" --msgbox "$str" 20 78

When I run this script I get error:

-|foo\n: unknown option

If I make change

str="+|foo\n"

then it succeeds.

Anyway I can circumvent this without changing str? Thanks.


Solution

  • The whiptail manpage (which should be available with the command man whiptail; if not, you can read it here) contains this note (in the Notes section):

    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.