[bash] pass argument containing spaces
In a shall script, I am building a parameter list for a later call:
Code:
opt="-option1 '60 0 50 0' -option2 ..." question: How can I force it to be recognized as one parameter? set-up: GNU bash, version 4.2.20(1)-release (i486-pc-linux-gnu) |
Hi,
Code:
convert "$opt" |
Thank you Chirel, but this passes the WHOLE content of $opt as one parameter.
I just want '60 0 50 0' recognized as one parameter. My attempt to place it in single quotes does not do the trick. What I need is: Code:
{-option1} |
Are you really limited to bash-only?
|
Go with an array:
Code:
opt=(-option1 '60 0 50 0' -option2 ...) |
Code:
eval convert $opt |
NevemTeve, eval was new to me and it does the trick.
grail: I am not quite sure what to do with the array: Code:
$ convert ${opt[@]} Code:
{-option1} |
Well my understanding was that you wanted the individual items to stay grouped together:
Code:
opt=(-option1 '60 0 50 0' -option2 ) |
And how do I pass the array to convert?
Which Perth, by the way? |
convert "${opt[@]}" # untested
|
That's what I described in post #7: it doesn't work; paramaters are split into words.
|
Quote:
Try adding quotes to the items required: Code:
$ opt=(-option1 "'60 0 50 0'" -option2 ) |
Now I tested it, with quotes it does work:
Code:
$ opt=(-option1 '60 0 50 0' -option2 ) |
OK, that's the array parameter passing sorted. Many thanks!
Quote:
|
All times are GMT -5. The time now is 06:33 AM. |