1.

Solve : How to pass argument containing quotes to batch script?

Answer»

Hi Friends,

Considering the following batch command invocation:

demo.bat I said, "you are so beautiful!"

In demo.bat, print the passed argument. The output should be:

I said, "you are so beautiful!"

Could you please help me implement this?

Thanks in advance!Try this workaround, not pretty but FUNCTIONAL.  Spaces will be added to the variable to make up the arguments which are not passed.  The maximum number of arguments is 9 until you use the Shift command.

Code: [Select]echo off
setLocal
cls

set this=%1 %2 %3 %4 %5 %6 %7 %8 %9

echo %this%

Syntax:  Batfilename I said, "The speed limit is 100 mph".

Output:  I said, "The speed limit is 100 mph".




 This is obviously homework. OH well though.

Code: [Select]echo off
echo %*
Quote from: BC_Programmer on December 10, 2010, 08:23:34 PM

This is obviously homework. Oh well though.
Code: [Select]echo off
echo %*
WOW!
This is the first time I saw BC pass an argument!  Thank you for the lesson BC_P.  I've noted that using %* allows for more than 9 variables to be used without the Shift command.

D. Quote from: BC_Programmer on December 10, 2010, 08:23:34 PM
This is obviously homework. Oh well though.

Code: [Select]echo off
echo %*

Hi BC_Programmer,

Thanks!

BTW, how to judge if the passed auguments equal to I said, "you are so beautiful!" in demo.bat file. Code: [Select]If "%*"=="you are so beautiful!" (echo Why thank you!) else (echo You know I'm beautiful, you just won't SAY it!")


Discussion

No Comment Found