Passing variable as an argument to another script

Hi,

I am trying to pass a variable as an argument to another script. While substitution of variable, I am facing a problem.
varaiable "a" value should be -b "FPT MAIN".
When we pass "a" to another script, we are expecing it to get substitue as ./test.sh -b "FPT MAIN". But, it is getting substituted as ./test.sh -b '"FPT' 'MAIN"', which is causing a problem.

Could someone suggest how to achieve this.

bash$ a=" -b \"FPT MAIN\" "; 
bash$ echo $a
-b "FPT MAIN"
bash$
bash$
bash$ a=" -b \"FPT MAIN\" "; echo $a ;set -x ; ./test.sh $a; set +x
-b "FPT MAIN"
+ ./test.sh -b '"FPT' 'MAIN"'
-b "FPT MAIN"
+ set +x
bash$
bash$
bash$ cat test.sh
#!/bin/bash
a=$@
echo $a

Try

a=" -b \"FPT MAIN\" "; echo $a ;set -x ; ./test.sh "$a"; set +x

--ahamed

Try this:

a=" -b \"FPT MAIN\" "; echo $a ;set -x ; eval ./test.sh $a; set +x

Andrew

Thanks for the reply.

But with the solution, getting additional single codes ./test.sh ' -b "FPT MAIN" '. This single quote is creating problem.

bash$ a=" -b \"FPT MAIN\" "; echo $a ;set -x ; ./test.sh "$a"; set +x
-b "FPT MAIN"
+ ./test.sh ' -b "FPT MAIN" '
-b "FPT MAIN"
+ set +x
bash$

---------- Post updated at 03:03 AM ---------- Previous update was at 03:01 AM ----------

This is just an example I have put.

Actually, I am passing $a to some python script, which needs argument in format -b "FPT2 Main" -e 1node_ran_ref -v 371145 -R

What is this problem being caused in the python script? Is it not able to parse it?

--ahamed

Yep.
bcoz of single quote, ' -b "FPT MAIN" '
it is not able to recognise arguments.

a="-b \"FPT2 Main\" -e 1node_ran_ref -v 371145 -R" ; echo $a ; set -x ;/build/fpsdkroot_extra/bin/cicli.py getlastCompleteOKbuild "$a" ; set +x
-b "FPT2 Main" -e 1node_ran_ref -v 371145 -R
+ /build/fpsdkroot_extra/bin/cicli.py getlastCompleteOKbuild '-b "FPT2 Main" -e 1node_ran_ref -v 371145 -R'
NO SUCH BRANCH
ERROR: 11: Branch object not found
+ set +x

-bash-3.00$ /build/fpsdkroot_extra/bin/cicli.py getlastCompleteOKbuild  -b "FPT2 Main" -e 1node_ran_ref -v 371145 -R
1node_ran_ref:
R_FPT_2.4.1.1.WR.64.rh.1309031601.371145
DEPLOYMENT:
create_1node_ran_ref.sh

-bash-3.00$

The problem is in how the shell is interpreting the $a at the invocation of the other script. $a is interpreted as 3 arguments because three are two whitespace in $a. "$a" is interpreted as a single argument because it sees the quotes around the $a. Use my solution: eval causes the shell to interpret the $a as two arguments, which is what you need.

Andrew

You will have to split it

a="-b"; b="\"FPT MAIN\" ";set -x ; ./test.sh $a "$b"; set +x

--ahamed

---------- Post updated at 01:27 AM ---------- Previous update was at 01:25 AM ----------

Or you can do it like Adrew said

--ahamed

Thanks Andrew.

It worked with eval.