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:
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:
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
Post a Comment