我试图使用whiptail做一个检查表,但是当我输入其中一个选项时,它会检测到它是一个命令,尽管它是用引号表示的。这个清单的要点是对文件进行bash处理,并在bash期间将变量添加到shell命令的末尾,即
bash something.sh -cached_var_here下面是代码和错误:
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
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
echo
./bench.sh $BENCH我知道这个错误:
You chose the following options: -info: unknown option发布于 2018-01-09 17:11:43
让我们参考man whiptail:
whiptail将以虚线"-“开头的参数解释为参数。为了避免这种情况,并在例如菜单框项目中使用破折号开始一些文本,whiptail遵守接受特殊参数"--“的getopt约定,这意味着下面所有带有破折号的参数都将被逐字处理,而不是被解析为选项。
因此,以下方法应该像魅力一样发挥作用:
whiptail --title "Choose Benchmark Options" --checklist -- Choose: 20 30 15 -info "System Information" offhttps://askubuntu.com/questions/993965
复制相似问题