I was trying to use the regular expression syntax from bash to match "one or more" of an item. (...) If the extglob shell option is enabled (...)

Thing is, you have to explicitly enable extended pattern matching, which is not enabled by default when the shell is run in non-interactive mode.

Both of these invocations do work for me:

my $r = `/bin/bash -O extglob -c 'echo mc-lang-+([^-])-+([^-])*.rpm'`; my $r = `/bin/bash -c 'shopt -s extglob\necho mc-lang-+([^-])-+([^-])* +.rpm'`;

(i.e., print $r would output mc-lang-4.6.1-140.x86_64.rpm, assuming a file with that name is in the current directory)

Note that when enabling extglob within the command sequence itself (shopt -s extglob, as opposed to the startup option -O extglob), you have to use \n as the statement separator, because when using a semicolon, the shell would parse the line in one go, and produce a syntax error before the shopt command gets a chance to take effect...

Interestingly, on Linux (where /bin/sh typically is a symlink to /bin/bash), the following does work too, for me:

my $r = `shopt -s extglob\necho mc-lang-+([^-])-+([^-])*.rpm`;

I say "interestingly", because when invoked through the name sh (as Perl does behind the scenes), bash will behave differently in several respects (i.e. it mimics the original bourne shell), which is why I would have expected it to not do extended pattern matching at all. Apparently, the latter is not the case.


In reply to Re^3: getting shell expansion to work by almut
in thread getting shell expansion to work by perl-diddler

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.