in reply to Re^2: getting shell expansion to work
in thread getting shell expansion to work
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: getting shell expansion to work
by perl-diddler (Chaplain) on Dec 28, 2007 at 20:58 UTC |