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

3
  • 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? Commented Oct 20, 2022 at 9:40
  • thanks compo I updated the question, %* not good because I do not want the first argument Commented Oct 20, 2022 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. Commented Oct 20, 2022 at 11:10

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.