1

how to pass a parameter with space or ; to function?

call :MyFunct "arg1" "arg2 arg2";"arg2"

:MyFunct

echo %~2

I would like to retrieve from %~1 "arg2 arg2";"arg2" but do not know how to do

zeus
  • 12,173
  • 9
  • 63
  • 184
  • But ```"one two";"tree"``` is two doublequoted arguments separated by a semicolon. `%~1` is the first argument, with any surrounding doublequotes removed. Have you tried `%*` for all of the arguments together? – Compo Oct 20 '22 at 09:40
  • thanks compo I updated the question, %* not good because I do not want the first argument – zeus Oct 20 '22 at 10:51
  • 1
    `%~1` is the first argument, (with enclosing doublequotes removed), `arg1`, `%~2` is the second argument, (with enclosing doublequotes removed), `arg2 arg2`, and `%~3` is the third argument, (with enclosing doublequotes removed), `arg2`. Spaces, commas and semicolons and even unquoted equals characters are considered as argument delimiters. How about you better show where the `call` argument string is coming from, and exactly what you wish to isolate from each part of it. – Compo Oct 20 '22 at 11:10

1 Answers1

1

For your sample "arg1" "arg2 arg2";"arg2" the arguments are

arg1="arg1"
arg2="arg2 arg2"
arg3="arg2"

That's simply the rule of cmd.exe, any unquoted delimiter in the arguments splits arguments, delimiters are <space>;,=

If you want a different behavior, you need to write your own parsing function on the basis of %* or even better on the bullet proof argument reading

jeb
  • 78,592
  • 17
  • 171
  • 225