windows - bat files, functions and caret symbols -


whats's going on?

helper.bat

@echo off echo %1 call:foo %1 goto:eof  :foo echo %1 goto:eof 

run our script following

helper "^^^^"

output

"^^^^"

"^^^^^^^^"

why? know '^' symbol smth special in case of cmd.exe, what's going on here? how function call affect on it?

call special in case!

the batch parser has different phases, in special character phase unquoted carets used escape next character, caret removed.
in case, carets quoted, not affected.

then carets can affected again in delayed expansion phase, quotes havn't special meaning there, carets used escape exclamation marks.

normally after delayed phase done, if use call carets doubled.
invisible, call restarts parser , carets removed in special character phase again.
in case quoted, therefore stay doubled.

try this

call call call call echo a^^ "b^" 

output

a^ "b^^^^^^^^^^^^^^^^" 

the parser explained @ how windows command interpreter (cmd.exe) parse scripts?


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -