DOS Command Switches - Use double quotes in switch arguments?

jdana
jdana used Ask the Experts™
on
I've been banging my head against the wall for the last two hours with a bcp call for MSSQL.

bcp MyDB.dbo.MyTable in "C:\..." -S MyServer\MyInstance -T -f "C:\MyBCPFormatFile.xml"

On a whim, I added double quotes to the argument associated with the server switch, and it worked! (Note the quotes around MyServer\MyInstance.)

bcp MyDB.dbo.MyTable in "C:\..." -S "MyServer\MyInstance" -T -f "C:\MyBCPFormatFile.xml"

Is it safe to always wrap the arguments associated with a switch (option) with double-quotes?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Trenton KnewOwner / Computer Whisperer
Commented:
Typically, you only need to fool with the quotes if your argument contains a space.  so C:\Users\Joe\Documents wouldn't need a quote, whereas "C:\Users\Joe\Documents\Float Trip" would.

there is also a difference, however between using single quotes vs double quotes.  Did any of your arguments originally contain a space?
"Batchelor", Developer and EE Topic Advisor
Top Expert 2015
Commented:
Sadly, each program can handle double quotes (and other quotes) as they like. In a cmd shell or batch it should be safe, however, to always use double quotes, There are exceptions. So: it depends.

You should not need to use double quotes for the server\instance in bcp, as you don't with sqlcmd or isqlw etc.

Author

Commented:
Thanks guys, Great feedback.

J

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial