Windows – How to make Windows command prompt treat single quote as though it is a double quote

command linewindows

My scenario is simple – I am copying script samples from the Mercurial online book 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.

Best Answer

The quoting character can't be changed in the command.com prompt. You can, however, use PowerShell which accepts both single and double quotes as quoting characters. They function the same as in Unix shells. I.e., single quotes do not expand variables while double quotes will.

You might still run into problems with quotes inside quotes. For example, I have strawberry perl installed on my Windows computer. When I run perl -e 'print time, "\n" ' in PowerShell, I see output such as 1321375663SCALAR(0x15731d4). I have to escape the double quotes for it to work as expected: perl -e 'print time, \"\n\" '