Quote problem



This has probably been asked before but I can't seem to find this
anywhere.

Can someone help me understand what I am seeing.

Lets start a session on cygwin...

set -x

# set $t to some sql preceded by a -Q flag. This will be passed to
another command obviously.

$ t=" -Q \"SELECT curriculum_last_update FROM application_settings\" "
+ t=' -Q "SELECT curriculum_last_update FROM application_settings" '

# So far so good

$ echo $t
+ echo -Q '"SELECT' curriculum_last_update FROM
'application_settings"'
-Q "SELECT curriculum_last_update FROM application_settings"

Notice the single-quote at the end of SELECT and at the beginning of
application_settings. Why does that happen?

# Make a call to sqlcmd. sqlcmd is a command line interface to sql
server. $t now contains the SQL
# that I would like to run, preceded by -Q which means "query"
$ sqlcmd -b -x -d mydb -S myserver $t
+ sqlcmd -b -x -d mydb -S myserver -Q '"SELECT'
curriculum_last_update FROM 'application_settings"'
Sqlcmd: 'SELECT" curriculum_last_update FROM "application_settings
\""': Unexpected argument. Enter '-?' for help.

sqlcmd seems to be getting a sql string that has a couple of
unnecessary quotes (not even sure if they are double or single
according to the output".

Oh well, I would love to know why this is happening. Thanks for your
help in advance.

.


Quantcast