Error with Linux whiptail/dialog arguments from bash variable

孤街浪徒 提交于 2019-12-12 11:46:10

问题


could someone explain why the code below doesn't work? I'm going crazy trying to find out.

#!/bin/bash

TEST="M1 \"1-wire Interface\" ON"
echo $TEST
RESULT=$(dialog --title "Config Modules State" --checklist "Choose modules to activate" 20 50 1 $TEST)

It prints this at the output, as expected:

M1 "1-wire Interface" ON

'dialog' gives an error saying:

Error: Expected 3 arguments, found only 1.

'whiptail' doesn't give any error but just exits listing out its options.

If I were to take the string that it printed, copy and paste it like this on the command line, it works:

dialog --title "Config Modules State" --checklist "Choose modules to activate" 20 50 1 M1 "1-wire Interface" ON

with both 'dialog' and 'whiptail'. What is going on?

System:

  • Linux raspberrypi 3.18.11+ #781 PREEMPT
  • whiptail (newt): 0.52.14
  • dialog Version: 1.1-20120215

回答1:


The answer from the comments if somebody comes across this.

TEST=(M1 '1-wire Interface' ON)
TEST=( "${TEST[@]}" M2 'Other Interface' OFF )
echo ${TEST[@]}
dialog --title "Config Modules State" --checklist "Choose modules to activate" 20 50 2 "${TEST[@]}"


来源:https://stackoverflow.com/questions/30146241/error-with-linux-whiptail-dialog-arguments-from-bash-variable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!