Error with Linux whiptail/dialog arguments from ba

2019-06-25 13:07发布

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条回答
▲ chillily
2楼-- · 2019-06-25 13:10

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[@]}"
查看更多
登录 后发表回答