It's important to know why as well.

In bash, the standard current Linux shell, your single quotes have to balance out. In your example above, you have three single quotes. Four of them would balance out, but not three. You can see this if you change your code:

perl -p -i -e 's/ where/' where/g' *.sql
to:
# Note the second single-quote below perl -pi.orig -e 's/ where/'' where/g' *.sql
This probably will not give you the results you expect (though it's "shell-correct"), because the quoting is actually still incorrect for your target results.

There is also an interesting change I put in the second example. Note the '-pi.orig' change there. What that does is create a file called 'foo.sql.orig' for every file changed by your substitution (assuming foo.sql was one of your files). When you're dealing with files and substitutions "in-place" like that, it's good to make a backup.

NOTE: If you run this a second time, your backup file will be overwritten by your second copy, trashing your backup. It's always good to have backups somewhere else, but if you're doing a one-time pass, using -pi.orig is a good way to do that.

The suggestion from Chmrr is correct in this case, you need to change how your quoting is passed to the shell. You do not have to do this if this change was inside a perl script running under bash, however.

There are several documents on the web that can help you understand this a bit more:

A Guide to Unix Shell Quoting

AWK shell quoting issues

Hope that helps.


In reply to Re: Inserting a single-quote into a file by hacker
in thread Inserting a single-quote into a file by chuntoon

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.