Whiptail detects hyphen in name as a command


Answer: 1

33 hours ago

I'm trying to make a checklist using whiptail but when I enter one of the options it detects it as a command, even though it's in quotes. The point with this checklist is to bash a file and have the variables added to the end of the shell command during the bash i.e.

bash something.sh -cached_var_here

Here is the code and the error:

BENCH=$(whiptail --title "Choose Benchmark Options" --checklist "Choose:" 20 
30 15 \
 "-info" "System Information" off \
 "-io" "System I/O Test" off \
 "-cdn" "CDN Test Download (200MB)" off \
 "-northamerica" "North-American Server Test Download (800MB)" off \
 "-europe" "European Server Test Download (900MB)" off \
 "-asia" "Asian Server Test Download (400MB)" off \
 "-b" "System Information, CDN Download Test & I/O Test" off \
 "-speed" "Network Speedtest Using speedtest-cli" off \
 "-share" "Share Your Results With Others!" off \
 "-help" "Help Menu. Do NOT Execute This With Other Options!" off \
 "-about" "Show About-Info. Do NOT Execute This With Other Options!" off \
3>&1 1>&2 2>&3)

echo "You chose the following options: $BENCH"

echo "Do you want to run CUSTOM benchmark and information? (y/n)? "
old_stty_cfg=$(stty -g)
stty raw -echo
answer=$( while ! head -c 1 | grep -i '[ny]' ;do true ;done )
stty $old_stty_cfg
if echo "$answer" | grep -iq "^y" ;then
  echo Yes;

  curl -LsO raw.githubusercontent.com/sayem314/serverreviewbenchmark/master/bench.sh; chmod +x bench.sh
  ./bench.sh $BENCH

I get this error:

You chose the following options: -info: unknown option

Answer: 2

34 hours ago

Let's consult 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.

Therefore, the following approach should work like a charm:

whiptail --title "Choose Benchmark Options" --checklist -- Choose: 20 30 15 -info "System Information" off
Added by: Miss Tara Jenkins

Popular Search

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 1 2 3 4 5 6 7 8 9