Am 30.01.2010 19:23, schrieb VDR User:
On Sat, Jan 30, 2010 at 3:07 AM, Udo Richter udo_richter@gmx.de wrote:
The correct way to place every array element as one parameter, without doing any additional whitespace separation, is this:
"$vdrbin" -L "$vdrlib" "${vdrplug[@]}"
In contrast, "${vdrplug[*]}" merges all to one parameter, ${vdrplug[@]} does another whitespace separation run.
What makes that "correct"? Just sounds like a different (and more complicated, ..I guess) way to accomplish the same end result, but no more "correct" then using double/single quotes.
Correct in the sense of using arrays to build up a command line, not in a sense of The One And Only Solution (tm).
I'm no bash expert but STRING="$STRING -P'asdf arg'" works equally as well as ARRAY=( "${ARRAY[@]}" <new item> ) in my experience. What am I missing?
Well, not much, except that I would do it this way:
PLUGINS[${#PLUGINS[*]}]="-Psoftdevice -vo xv:full -ao alsa:mixer:pcm=default"
For a more complex (and a bit constructed) case:
PLUGINS="$PLUGINS -P"hello --aaa=\"A B C\""" or PLUGINS="$PLUGINS -P'hello --aaa="A B C"'" or PLUGINS[${#PLUGINS[*]}]="-Phello --aaa="A B C"" or PLUGINS[${#PLUGINS[*]}]="-Phello --aaa='A B C'"
Arrays have the advantage that they spare one level of quoting, don't need eval, and are a bit more 'ordered', but on the other hand are bash-only, and cannot be exported to sub-shells.
(runvdr extreme has a quoting function, so you do it with even less quoting like this: AddPlugin hello --aaa="A B C")
Cheers,
Udo