Home > Software engineering >  String starting with hyphen minus fails with whiptail
String starting with hyphen minus fails with whiptail

Time:08-17

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.

CodePudding user response:

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.

CodePudding user response:

I can just use textbox instead.

whiptail --title "test" --textbox foo.txt 20 78
  • Related