Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: something simple (I hope)



On Aug 4,  5:38pm, Andy Spiegl wrote:
} Subject: Re: something simple (I hope)
}
} > > I want to put all files that match the regex pattern
} > >  "^/var/tmp/exec\.[0-9]+$"
} > > into a list that I can then use in a foreach loop.
} 
} Actually in the meantime I found out how to do that:
}  files=(/var/tmp/exec.[[:digit:]]*)
} 
} But what is still bugging me is that this also matches files like
}  /var/tmp/exec.01234.something
} 
} I can't figure out how to tell zsh that there shouldn't be anything _after_
} digits.  What is the zsh-equivalent of a $ in regular expressions?

All glob patterns are implicitly anchored at start and end; there's no
such thing as a file glob that matches anywhere in a file name.

What you've forgotten is that * in a glob pattern is equivalent to .*
in a regular expression.  It's # in zsh that repeats the preceeding
glob pattern.  So what you want is

setopt extendedglob
files=( /var/tmp/exec.[[:digit:]]# )



Messages sorted by: Reverse Date, Date, Thread, Author