I am using ubuntu and using "/bin/bash" as my default bash. I have a simple c program (test_arg.c) that prints the arguments.
#include <stdio.h>
void
main(int argc, char **argv)
{
for(int i=0; i < argc; i++) {
printf("arg[%d]:%s \n", i, argv[i]);
}
}
When I try to pass an argument that has a double quote, it works fine.
ubuntu@ubuntu:~$ ./test_arg.out 1 2 3 "4 5 6"
arg[0]:./test_arg.out
arg[1]:1
arg[2]:2
arg[3]:3
arg[4]:4 5 6
If I use a bash variable to store the arguments then it doesn't work as expected.
ubuntu@ubuntu:~$ arg="1 2 3 \"4 5 6\""
ubuntu@ubuntu:~$ ./a.out $arg
arg[0]:./a.out
arg[1]:1
arg[2]:2
arg[3]:3
arg[4]:"4
arg[5]:5
arg[6]:6"
I have to use a variable to store the arguments. I tried different options but failed. Appreciate any suggestions.