zsh-users
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.stephenson@samsung.com>
To: Brent Briggs <brent.briggs@gmail.com>, zsh-users@zsh.org
Subject: Re: Glob problem
Date: Tue, 22 Oct 2013 17:59:27 +0100	[thread overview]
Message-ID: <20131022175927.6de9a441@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <F814E825-D3A5-420E-B289-6D3B0FB47D75@gmail.com>

On Tue, 22 Oct 2013 12:45:48 -0400
Brent Briggs <brent.briggs@gmail.com> 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


  parent reply	other threads:[~2013-10-22 17:09 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-22 16:45 Brent Briggs
2013-10-22 16:58 ` Jérémie Roquet
2013-10-22 16:59 ` Peter Stephenson [this message]
2013-10-22 17:05 ` Philippe Troin
2013-10-22 18:02   ` Brent Briggs
2013-10-22 18:12     ` Peter Miller
2013-10-22 18:49       ` Brent Briggs
2013-10-22 19:30         ` Peter Miller
2013-10-22 20:11         ` Yuya Amemiya
2013-10-23 12:27           ` Brent Briggs
2013-10-23 12:37             ` Jérémie Roquet
2013-10-23 13:47             ` Peter Stephenson
2013-10-23 14:29             ` Yuya Amemiya
2013-10-22 17:11 ` Matt Garriott

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20131022175927.6de9a441@pwslap01u.europe.root.pri \
    --to=p.stephenson@samsung.com \
    --cc=brent.briggs@gmail.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).