-
Notifications
You must be signed in to change notification settings - Fork 4
How quotes can break batch scripts
johnstevenson edited this page Aug 4, 2016
·
1 revision
Although surrounding each argument with double-quotes can be a safe method of escaping, it can also have its pitfalls.
When cmd.exe is processing a batch file it handles the expansion of the script's arguments, referenced %0 %1 %2
etc. If the argument is a file name, then the %~
syntax can be combined with various modifiers to produce path information. For example:
-
%~f0
expands to the fully-qualified name of the current script. -
%~dp0
expands to the drive and path of the current script.
However, if a batch script invocation requires a PATH
lookup and the file name is double-quoted, these expansions will fail and reference the current working directory, rather than the actual script directory. This will obviously cause problems if the script tries to call something it knows is in the same directory as itself.