[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: pbuilder

Hi Dale,

> Anyone know how to make bash do a regexpr in a conditional?  I want to
> filter out *~ *.bak and such. Perl would do it roughly something like
> this (without bothering to check perlreg and perlop)
> if ( "*~"    =~ $file) {next;}
> if ( "*.bak" =~ $file) {next;}

You can use POSIX.2 basic regexp in bash(1).

I suppose you simply scan through all your files in hooks/ and want to
skip all backup files and such. It depends when you want to use that,
which pattern expansion/matching rules apply.

case uses "pathname expansion" as matching rules.

-- first scenario --
cd hooks/
for file in * ; do
  case $file in
      echo "W: Skip $file, seems to be a backup"
      do_1st $file
      do_2nd $file
      echo "Oops. Didn't recognize it."
-- end --

If you always do the same but want to skip only the backup-files you may
do something like this:

-- 2nd scenario --
cd hooks/
shopt -s extglob
for file in !(*~|*.bak) ; do
shopt -u extglob
-- end --

Or you use GLOBIGNORE by specifying a colon seperated list of patterns
that should be ignored during pathname expansion. Don't forget to unset
GLOBIGNORE afterwords:

-- 3rd scenario --
cd hooks/
for file in * ; do
-- end --

For your problem, I would still prefer the 1st scenario with just a
default case-switch and another for the backup files (because it works
using the ash as well).

Well, play around with it some more. Since bash2 you can do almost
everything (well, erverything but fast scripts). Install bash-doc and have
a look at the examples.

Kind regards,

ruehmkorf at informatik dot uni hyphen koeln dot de

Reply to: