bash - How to quote variables in a whiptail command with dynamic/conditional options? -


i need disable options in dialog command built in bash script. here original working script:

my_backtitle="this test" selected_options=($(dialog \     --backtitle "$my_backtitle" \     --separate-output \     --checklist "select options:" 0 0 \     "option1" "description of option 1" "" \     "option2" "description of option 2" "" \     3>&1 1>&2 2>&3)) 

then selected options directly in array.

in cases need disable of options. i've tried way:

my_condition=false my_backtitle="this test" dialog_parameters="--backtitle '" dialog_parameters+="$my_backtitle" dialog_parameters+="' --separate-output \     --checklist "select options:" 0 0 " if $my_condition     dialog_command+="'option1' 'description of option 1' '' " fi dialog_command+="'option2' 'description of option 2' ''" selected_options=($(dialog $dialog_parameters 3>&1 1>&2 2>&3)) 

but error: error: unknown option is.

with debugging set -e parameter, see dialog command after parameters expansion: dialog --backtitle ''\''this' 'test'\''' --separate....

how can quote correctly string containing spaces in case?

i've tried using \" around variable, , tried storing parameters in array of strings, did not solve problem.

how should write such parametrized dialog command?

you need use array, not string, hold individual arguments may contain whitespace.

my_condition=false my_backtitle="this test" args=(--backtitle "$my_backtitle") args+=(--separate-output) args+=(--checklist "select options:" 0 0) if $my_condition     args+=( "option1" "description of option 1" ) fi args+=('option2' 'description of option 2') selected_options=($(dialog "${args[@]}" 3>&1 1>&2 2>&3)) 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -