Neoon Neoon - 1 year ago 97
Bash Question

Passing params to another Bash file, with spaces

I want to pass several parameters from one Bash file to another, the problem is, it seems to ignore my quote marks, I dont want to pass it with


Here is my current setup:



RESP='command start Test "srcds_run -game garrysmod +maxplayers 32 +map gm_construct"'

./ ${KEY} ${RESP}

Actually the
is coming from a CURL but that gives me the same result.


echo $1;
echo $2;
echo $3;
echo $4;
echo $5;

And guess,
gives me:


instead of

srcds_run -game garrysmod +maxplayers 32 +map gm_construct

what I actually wanted.

So when using
it gives me all parameters, fine but I want them splitted, same as using
, I do overwrite the parameters at the script but that turns all parameters into
and I want them splitted...

So any solution to pass Parameters with Spaces without issues?

Answer Source

In this case you have to use an array (and more quotes):



resp=( command start Test "srcds_run -game garrysmod +maxplayers 32 +map gm_construct" )

./ "$key" "${resp[@]}"

Note that I used lowercase variable names (which is good practice!).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download