How to make Windows command prompt treat single quote as though it is a double quote?
Posted
by
mark
on Super User
See other posts from Super User
or by mark
Published on 2011-08-17T11:05:52Z
Indexed on
2011/11/15
17:56 UTC
Read the original article
Hit count: 206
Windows
|command-line
My scenario is simple - I am copying script samples from the Mercurial online book (at http://hGBook.red-bean.com) and pasting them in a Windows command prompt. The problem is that the samples in the book use single quoted strings. When a single quoted string is passed on the Windows command prompt, the latter does not recognize that everything between the single quotes belongs to one string.
For example, the following command:
hg commit -m 'Initial commit'
cannot be pasted as is in a command prompt, because the latter treats 'Initial commit'
as two strings - 'Initial
and commit'
. I have to edit the command after paste and it is annoying.
Is it possible to instruct the Windows command prompt to treat single quotes similarly to the double one?
EDIT
Following the reply by JdeBP I have done a little research. Here is the summary:
Mercurial entry point looks like so (it is a python program):
def run(): "run the command in sys.argv" sys.exit(dispatch(request(sys.argv[1:])))
So, I have created a tiny python program to mimic the command line processing used by mercurial:
import sys print sys.argv[1:]
Here is the Unix console log:
[hg@Quake ~]$ python 1.py "1 2 3" ['1 2 3'] [hg@Quake ~]$ python 1.py '1 2 3' ['1 2 3'] [hg@Quake ~]$ python 1.py 1 2 3 ['1', '2', '3'] [hg@Quake ~]$
And here is the respective Windows console log:
C:\Work>python 1.py "1 2 3" ['1 2 3']
C:\Work>python 1.py '1 2 3' ["'1", '2', "3'"]
C:\Work>python 1.py 1 2 3 ['1', '2', '3']
C:\Work>
One can clearly see that Windows does not treat single quotes as double quotes. And this is the essence of my question.
© Super User or respective owner