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

Re: Glob problem



On Tue, 22 Oct 2013 12:45:48 -0400
Brent Briggs <brent.briggs@xxxxxxxxx> wrote:
> I am simply trying to list all matches for a specified pattern in an
> array of directory paths, the $path array for example. Here is my
> attempt. Where am I going wrong?

I'm sure someone will beat me to it...

> pattern=git*

It's not the source of the problem, but it's generally safer to quote
literal patterns if you don't want them expanded at that point.
Actually, you can't get a glob here unless you have the GLOB_ASSIGN
option set.

> for entry in $path
> do
>     # Print all files in the path that match the pattern. 
>     print $entry/$pattern
> done

$pattern is the literal string "git*" in zsh and doesn't get expanded
further.

If you like the way other shells work, use (globally)

  setopt globsubst

However, most of us find it a pain having to remember to quote variables
every time we we want them to be substituted literally (which most other
languages would do automatically).

The zsh-specific way to tell it you want pattern characters to be
special is:

  print $entry/${~pattern}

pws



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