The difference is that the command zenity
sees multiple arguments in the first case, and only one (including a lot of spaces) in the second.
With the following awk
program, you can quickly output what the shell expands the arguments to. As it happens, zsh
I could reproduce your problem:
% awk 'BEGIN {for (i in ARGV) print "ARGV["i"] =", ARGV[i]}' $ZEN
ARGV[0] = awk
ARGV[1] = --info --text "pure info" --title "get info"
Whereas in bash
it looks almost like it should look (notice that the quoted strings are split in words):
$ awk 'BEGIN {for (i in ARGV) print "ARGV["i"] =", ARGV[i]}' $ZEN
ARGV[0] = awk
ARGV[1] = --info
ARGV[2] = --text
ARGV[3] = "pure
ARGV[4] = info"
ARGV[5] = --title
ARGV[6] = "get
ARGV[7] = info"
There should be a shell word splitting option responsible for this behavior.
This, however, worked:
set -- --info --text "pure info" --title "get info"
zenity "$@"
Edit:
Shells are a bit stupid with word splitting by default, see the behavorior in my bash
example above: "pure
and info"
are two separate words. As this is annoying in parsing of command line options, some special functionality has been created in the treatment of "$@
. Quoting the bash
manual, section Special Parameters:
@ Expands to the positional parameters, starting from one. When
the expansion occurs within double quotes, each parameter
expands to a separate word. That is, "$@" is equivalent to "$1"
"$2" ...
I have not found a way to get the special treatment of $@
into normal variable expansion, but there could be a trick.
The set
command sets the positional parameters, $1
, $2
, .... As such, the "Give me all"-version of positional parameters, $@
, is available as well.
ZEN=(--info --text "pure info" --title "get info"); zenity "${ZEN[@]}"
– Gilles 'SO- stop being evil' Jul 14 '15 at 15:08