问题
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