bug-bash
[Top][All Lists]
Advanced

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

Re: How to create bash-pattern to exclude a matching param in param expa


From: Peggy Russell
Subject: Re: How to create bash-pattern to exclude a matching param in param expansion&matching?
Date: Wed, 30 Oct 2013 08:01:02 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

> I am missing how to create a bash-pattern that excludes a specific
pattern.
> 
> I.e. to ignore any file with '-IGN-' somewhere in the filename.
> 
> The best I've come up with so far has been to use shell to build
> a pattern, but I know it is limited in functionality.  I.e.:
> 
> ls !($(echo *+(-IGN-)*|tr " " "|"))
> 
> I tried the above in a dir that has 2 files w/the pattern, and
> 532 w/o, and it worked, but how much of that was 'luck'?
> 
> Is there a better bash-pattern that doesn't use tr and such?

A variation:
 
shopt -s nullglob
for f in ${1:-.}/*; do
  if [[ "${f}" != *-IGN-* ]];
    then printf -- '%s\n' "${f}"
  fi
done

Peggy Russell






reply via email to

[Prev in Thread] Current Thread [Next in Thread]