tags:

views:

31

answers:

2

Hello, 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.

Thanks

+3  A: 

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"

Jeff M
A: 

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
Ankur Agarwal
This should have been posted as an edit to your original question. Also, I can't see how this relates to your question. There's no `getopt` or date. The third line looks like it might be generally the type of format that will work, though.
Dennis Williamson