Hello, in this example of starting VDR in a script some options are passed to the softdevice plugin:
$vdrbin -L $vdrlib -Pfemon -P"softdevice -vo xv:full -ao alsa:mixer:pcm=default"
Now I want a variable or array at the top of the script so I could easily add, remove and comment plugins... rewriting the above example:
vdrplug=(-Pfemon -P"softdevice -vo xv:full -ao alsa:mixer:pcm=default" ) $vdrbin -L $vdrlib ${vdrplug[@]}
I have tried numerous ways of quoting and escaping the softdevice line but I always get one of:
1. VDR tries to start a plugin called: "softdevice 2. VDR interprets -v in -vo as VDR video directory option and fails because there is no directory "o"
Can anyone help me with writing this? I use vdr 1.6.0, thanks,
Use double-quotes to surround your plugins and single-quotes for plugin options. For example:
VDR="$vdrbin -L $vdrlib" PLUGINS="-Pfemon -P'softdevice -vo xv:full -ao alsa:mixer:pcm=default'" eval "$VDR $PLUGINS" &
Am 25.01.2010 00:19, schrieb Adrian C.:
Now I want a variable or array at the top of the script so I could easily add, remove and comment plugins... rewriting the above example:
vdrplug=(-Pfemon -P"softdevice -vo xv:full -ao alsa:mixer:pcm=default" ) $vdrbin -L $vdrlib ${vdrplug[@]}
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.
runvdr extreme also uses a bash array for building the command line.
Cheers,
Udo
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.
runvdr extreme also uses a bash array for building the command line.
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.
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?
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