I want to pass the date entered by a user in format YYYY/MM/DD HH24:MI:SS to the C program which further makes the entry in the DB. When I am passing the entered date in the command line argument as '2010/07/15 12:13:14', the C program considers this as 2 arguments and not 1. We are using getopt function to fetch the command line argument. Also tried sending the date in " " qootes also. Can anyone help me so that the complete argument will be treated as 1 and not 2.
Th开发者_C百科anks
Below is the piece of code that I am executing:
name="Rahul+Kapgate arg"
temp=$name
./a.out -a "$temp"
#temp1="-a \"$name\""
#temp1=`echo $temp |sed 's/ /+/g'`
cmd="a.out -a \"${temp}\""
echo $cmd
exec $cmd
Output
Rahul+Kapgate arg
a.out -a "Rahul+Kapgate arg"
"Rahul+Kapgate
You need to wrap the entire input in double quotes so it would be interpreted as one.
e.g., program "2010/07/15 12:13:14"
精彩评论