tags:

views:

38

answers:

3
name="Rahul Kapgate arg"
temp=$name
./a.out -a "$temp"

This will give me a following output :: Rahul Kapgate arg

Instead of ./a.out -a "$temp" if i put following logic then it is generating differant output.

cmd="./a.out -a \"$temp\""
$cmd

Output :: "Rahul

[ a.out is nothing but the printing the 1st parameter through C unsing optarg())

I am expecting to generate the same output using 2nd option plz help me.

+4  A: 

Bash FAQ entry #50

Ignacio Vazquez-Abrams
Will you please explain mi using my example
rahul
A: 

It seems you are bypassing some of the shell processing. Try this:

echo $cmd | bash -s
Amardeep
A: 

As the information in the link provided by Ignacio indicates, you should try to avoid putting commands in variables. However, this may work for you (based also on information there):

cmd="./a.out"
args=(-a "$temp")
$cmd "${args[@]}"
Dennis Williamson