Explaining the question through examples...
Demonstrates that the single-quotes after --chapters is gets escaped when the variable is expanded (I didn't expect this):
prompt@ubuntu:/my/scripts$ cat test1.sh #!/bin/bash actions="--tags all:" actions+=" --chapters ''" mkvpropedit "$1" $actions prompt@ubuntu:/my/scripts$ ./test1.sh some.mkv Error: Could not open '''' for reading. And now for some reason mkvpropedit receives the double quotes as part of the filename (I didn't expect this either):
prompt@ubuntu:/my/scripts$ cat test1x.sh #!/bin/bash command="mkvpropedit \"$1\"" command+=" --tags all:" command+=" --chapters ''" echo "$command" $command prompt@ubuntu:/my/scripts$ ./test1x.sh some.mkv mkvpropedit "some.mkv" --tags all: --chapters '' Error: Could not open '''' for reading. The above echo'd command seems to be correct. Putting the same text in another script gives the expected result:
prompt@ubuntu:/my/scripts$ cat test2.sh #!/bin/bash mkvpropedit "$1" --tags all: --chapters '' prompt@ubuntu:/my/scripts$ ./test2.sh some.mkv The file is being analyzed. The changes are written to the file. Done. Could anyone please explain why the quotes are not behaving as expected. I found searching on this issue difficult as there are so many other quoting discussions on the web. I wouldn't even know how to explain the question without examples.
I am afraid that some day the file name in the argument contains some character that breaks everything, hence the maybe excessive quoting. I do not understand why the same command executes differently when typed directly in the script or when provided via a variable. Please enlighten me.
Thanks for reading.