Consider passing some set of arguments to a function, e.g.:
awk -vv1="Hello there" -vv2=Bye 'BEGIN {print v1,v2}'
Note that the first argument contains a space. The output is:
Hello there Bye
Now, I try to store the arguments in a variable. Consider first the case without a space in the first argument:
arg="-vv1=Hello -vv2=Bye"
awk $arg 'BEGIN {print v1,v2}'
This works fine. Now insert the space in the variable:
arg="-vv1='Hello there' -vv2=Bye"
awk $arg 'BEGIN {print v1,v2}'
which gives the error message:
awk: there'
awk: ^ invalid char ''' in expression
What is happening here?
Update
Based on the comments so far, I would like to refine my question:
Consider the case where arg
is the output of another shell script.
For instance, assume that genArg
is a shell script that prints the string:
"-vv1='Hello there' -vv2=Bye"
to the terminal. Then arg
is collected (in a script) like
arg=$(genArg)
and next I would like to call awk
with the given arguments:
awk $arg 'BEGIN {print v1,v2}'