command line - Zenity list dialog from variables - Ask Ubuntu


i have bash script looks this:

column_names="--column=\"targetdir\" --column=\"targetpage_id\" --column=\"targettitle\"" row="\"target dir 1\" 1 \"targettitle 1\""  echo "column_name is: [$column_names]" echo "row is: [$row]"  zenity --list --title="list" $column_names $row 

but when run that, see strange dialog:

enter image description here

you can see there 2 rows displayed instead of 1 (each word unidentified value of column). output in terminal:

column_name is: [--column="targetdir" --column="targetpage_id" --column="targettitle"] row is: ["target dir 1" 1 "targettitle 1"] 

but when copy printed values of column_name , row in terminal in way:

zenity --list --title="list" --column="targetdir" --column="targetpage_id" --column="targettitle" "target dir 1" 1 "targettitle 1" 

i true list dialog:

enter image description here

what wrong in script?

when you're building command line, use arrays. saves lot of trouble in quoting:

column_names=(--column=targetdir --column=targetpage_id --column=targettitle) row=("target dir 1" 1 "targettitle 1") 

note how necessary quotes (to protect spaces) left now.

when using array a, "${a[@]}" expand elements is, without causing problems whitespace. so:

zenity --list --title="list" "${column_names[@]}" "${row[@]}" 

try running printf instead of echo using original variables, might see breaks:

printf "%s\n" $column_names $row 

i'm not going try explain broke in original quoting. :shudder:


Comments

Popular posts from this blog

download - Firefox cannot save files (most of the time), how to solve? - Super User

windows - "-2146893807 NTE_NOT_FOUND" when repair certificate store - Super User