FAQ 3.25 Why don't Perl one-liners work on my DOS/Mac/VMS system?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with Perl.


3.25: Why don't Perl one-liners work on my DOS/Mac/VMS system?

    The problem is usually that the command interpreters on those systems
    have rather different ideas about quoting than the Unix shells under
    which the one-liners were created. On some systems, you may have to
    change single-quotes to double ones, which you must *NOT* do on Unix or
    Plan9 systems. You might also have to change a single % to a %%.

    For example:

        # Unix
        perl -e 'print "Hello world\n"'

        # DOS, etc.
        perl -e "print \"Hello world\n\""

        # Mac
        print "Hello world\n"
         (then Run "Myscript" or Shift-Command-R)

        # MPW
        perl -e 'print "Hello world\n"'

        # VMS
        perl -e "print ""Hello world\n"""

    The problem is that none of these examples are reliable: they depend on
    the command interpreter. Under Unix, the first two often work. Under
    DOS, it's entirely possible that neither works. If 4DOS was the command
    shell, you'd probably have better luck like this:

      perl -e "print <Ctrl-x>"Hello world\n<Ctrl-x>""

    Under the Mac, it depends which environment you are using. The MacPerl
    shell, or MPW, is much like Unix shells in its support for several
    quoting variants, except that it makes free use of the Mac's non-ASCII
    characters as control characters.

    Using qq(), q(), and qx(), instead of "double quotes", 'single quotes',
    and `backticks`, may make one-liners easier to write.

    There is no general solution to all of this. It is a mess.

    [Some of this answer was contributed by Kenneth Albanowski.]


Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short.  They represent an important
part of the Usenet tradition.  They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.

If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile.  If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.

Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release.  It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.

The perlfaq manual page contains the following copyright notice.


    Copyright (c) 1997-2002 Tom Christiansen and Nathan
    Torkington, and other contributors as noted. All rights

This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.

Site Timeline