I have spend hours searching for the answer to this problem, so now I have found it I will post it. Demonstrate problemSuppose I have a program that takes an option in the form: myprog -t "Title of Document" To test this we will create a script: #!/bin/bash echo option: «$1», title: «$2», ignore: «$3» When we run it we get: ./testopt.sh -t "Title of Document" >> option: «-t», title: «Title of Document», ignore: «» The problem shows up if instead of passing the arguments directly, we use a variable: opt='-t "Title of Document"' ./testopt.sh $opt >> option: «-t», title: «"Title», ignore: «of» Reasons for ProblemBash parses the line in multiple passes. Grouping into tokens using " is done before variable expansion, so the grouping withing the opt variable is ignored. This is documented very well here:
Solution
eval ./testopt.sh $opt >> option: «-t», title: «Title of Document», ignore: «»
|
|||