SPUG: One-liners on Windows via command.com

Johnston, Mark mark.johnston at pnl.gov
Wed Mar 23 13:21:09 PST 2005


	It doesn't appear that SQs are a special character at all in the
Windows command shell.  For confirmation, I tried the following Windows
Shell command

     for %f in ('print "Crikey";') do echo .%f.

The result was three separate arguments being echoed to the display (the
semi-colon being treated as a separator within the IN clause).  The
following command

     for %f in ('print "Crikey"'') do echo .%f.

echoes only two arguments.

	Microsoft has online documentation for the command shell
(CMD.exe) at
overview.asp and


-----Original Message-----
From: spug-list-bounces at pm.org [mailto:spug-list-bounces at pm.org] On
Behalf Of Tim Maher
Sent: Wednesday, March 23, 2005 10:33 AM
To: spug-list at pm.org
Subject: SPUG: One-liners on Windows via command.com

Can somebody give me pointers on how to modify Unix-ish one-liners to
work on Windows systems?

For example, this works on UNIX/Linux, because the single quotes (SQs)
are recognized as forming a literal string out of their contents, which
gets passed as an argument to the command:

perl -wle 'print "Crikey";'	

On Win/XP, the same command elicits this Perl error:

C:\ perl -wle 'print "Crikey";'	
Can't find string terminator "'" anywhere before EOF at -e line 1.

I had expected some indication that command.com wouldn't know what to do
with the SQ, as opposed to an indication that Perl only got a single one
in -e's argument!  Can somebody explain what SQs do in this shell?

On the other hand, I find that DQs as exterior quotes work fine (on XP),
and the backslash even appears to quote nested DQs, as it does in the
Unix shells:

C:\ perl -wle "print \"Crikey\";"	

and qq operator works:

C:\ perl -wle "print qq{Crikey};"	

as does the arguably more appropriate q operator:

C:\ perl -wle "print q{Crikey};"	

or the SQ itself:

C:\ perl -wle "print 'Crikey';"	

So now I'm wondering, do DQs in this shell allow any interpolations? 
If so, what Perl symbols would need to be quoted to suppress that?
Where does one get documentation on the workings of this shell?

"man perlport" provides lots of info on modifying Perl programs
/themselves/ for portability, but it has virtually nothing to say on the
subject of passing Perl code as a command-line argument.

Can somebody point me to their favorite tutorial covering the use of
command-line Perl techniques with Win32 systems?

| Tim Maher, PhD     (206) 781-UNIX      (866) DOC-PERL     (866)
| tim(AT)Consultix-Inc.Com  http://TeachMePerl.Com  
| http://TeachMeUnix.Com |
|    Watch for my June, 2005 book: "Minimal Perl for UNIX/Linux People"
Seattle Perl Users Group Mailing List  
     POST TO: spug-list at pm.org
SUBSCRIPTION: http://mail.pm.org/mailman/listinfo/spug-list
    MEETINGS: 3rd Tuesdays, Location: Amazon.com Pac-Med
    WEB PAGE: http://seattleperl.org/

More information about the spug-list mailing list