Escaping spaces in windows command line
Each individual double quote character by itself acts simply as a switch to enable or disable the recognition of space as a divider between arguments.
Attempting to find pairs of double quote characters that enclose meaningful chunks of text is possibly the biggest conceptual mistake that people make when looking at a complicated command line. In other contexts the parser treats these same characters like regular text. So at any given time the parser is in one of two states— recognizing i.
In order to be explicit when referring to these two states in the text, I invented names for them. They correspond to what some writers refer to as being outside or inside a double quoted string.
I purposely avoided giving them names containing quote or quoting because doing so reinforces the misconception that double quote characters somehow delineate arguments. The colors shown are used later to show the parser state in images I created to demonstrate how example command lines are parsed.
I originally considered calling these InterpretWhitespace and IgnoreWhitespace , but I wanted to use the same state names when discussing cmd. The key to understanding any command line, no matter how complex, is to pay attention to which of these two states the parser is in at any given time and understanding what causes the state to change.
The special character that we will see either interpreted or ignored , depending on the parser state, is the space character. Each line below represents a single character read from the command line.
The first column is the actual character read, followed by the parser state before processing the character, the action that was taken, and the value of the partial argument after processing the character. Enabling or disabling the recognition of special characters switching between InterpretSpecialChars and IgnoreSpecialChars is done by strategically placing double quote characters at specific locations on the command line— wherever you want the state to change.
This is under the control of the person who writes the command line. The act of placing double quote characters for this purpose is how I define the term quoting. It is not the delineation of a piece of text by enclosing it in a pair of double quote characters. Quoting is the placement of individual double quote characters on the command line to control the switching between InterpretSpecialChars and IgnoreSpecialChars. Since double quote characters work individually and not in pairs, there are no such concept as a dangling unclosed or mismatched quote as discussed by other writers.
The command line parser simply ends in one or the other of the two states. If there is an even number of un-escaped double quote characters on the command line we will define escape later the parser ends in InterpretSpecialChars.
If there is an odd number of un-escaped double quote characters it ends in IgnoreSpecialChars. By training your mind to scan a command line from left to right like the parser does, instead of trying to pick out the quoted chunks , you will have little problem understanding or correctly generating even the most complicated command line. To treat a percent as a regular character, double it:. When the shell is running in EnableDelayedExpansion mode the! This changes slightly if you are running with DelayedExpansion of variables: if any part of the command line includes an '!
For consistency, we recommend you stick with double quotes in the Command Prompt—or switch to PowerShell and use the grave accent method below.
Each grave accent character tells PowerShell to escape the following character. Note that this only works in the PowerShell environment. Source : how to geek. That is the whole problem and in my opinion it shoulb be able to handle spaces if it only expects a filepath anyways. So I am now just starting Rhino with a Pythonscript that then does all the necessary steps to do in Rhino using rs. Command like this:.
0コメント