From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12553 invoked by alias); 7 May 2015 14:36:05 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 20186 Received: (qmail 12493 invoked from network); 7 May 2015 14:36:03 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=6JFYuth2mVrHB8D5gZVyaBcM/YaplQvkEIlt5nHtsJM=; b=mblHcpXpAj48UQ48UOF2pEBC6RxK4Pc5Lp3PrM0OIcIFM+mvogL3aVYMHPMUeDqmiA 7x5QzsOLoahih27UsZ1oaIAJ4OFiZ+cRIbCRz3Ibmy5hf8zqGKUS13FirFvgC1kQ/IkD mjhJxC+4NMH5+Qd41IeoHjRM+56PPI6AthYuEZpwT7KzW6U0dP3F3UZIWkO3QRiNRxi0 y77MGqhqMx24LjggwpS0gY/k+mHG6WKdKuzQh62awQYIkx6pKxkLMdYSrK93IXWLyynP o5Rv/Secd8mvlinbT1xzJZl7EK0OR1mFWvzRjrEkwacQ6RNdaozc5V9zOobOGlvNp140 hiHw== MIME-Version: 1.0 X-Received: by 10.152.29.67 with SMTP id i3mr3363702lah.64.1431009357994; Thu, 07 May 2015 07:35:57 -0700 (PDT) Date: Thu, 7 May 2015 16:35:57 +0200 Message-ID: Subject: Some problems with recursive globbing From: =?UTF-8?Q?Jesper_Nyg=C3=A5rds?= To: Zsh Users Content-Type: multipart/alternative; boundary=089e0160b60074202805157ed48c --089e0160b60074202805157ed48c Content-Type: text/plain; charset=UTF-8 I am trying to write a function where I collect files within a file tree to do some processing. My goal is to find all files which are not in any directory called 'target', at any level. Here's a simplified version of my function: myfiles() { setopt LOCAL_OPTIONS EXTENDED_GLOB local dir [[ -n $1 ]] && dir=${1:a}/ local filepattern="${dir}**/*~${dir}(**/|)target(/**/*|/*|)" print -c ${~filepattern} } So this prints out the relative paths of all files in the current directory. If a directory is given as an argument, the absolute paths are printed of files within the given directory. (I know there's no check that the argument is actually a directory). This works, sort of, but I have a question and a problem. Question: I found it surprisingly difficult to to find a glob pattern that excluded target directories and their contents at all levels. Have I complicated this too much, is there an easier way to express this glob? Problem: I can't get this to work for both cases of a) directories with spaces in their names and b) directories with parenthesis in their names Suppose I'm standing in a directory called "/tmp/test(1)", and this directory contains a directory called "src". % myfiles src I get this: myfiles:9: no matches found: /tmp/test(1)/src/**/*~/tmp/test(1)/src/(**/|)target(/**/*|/*|) If I change the fifth line in myfiles() to this: [[ -n $1 ]] && dir=${(q)1:a}/ it works for the root directory with parentheses. However, standing in a directory called "/tmp/test 1", I now get this: myfiles:9: no matches found: /tmp/test\ 1/src/**/*~/tmp/test\ 1/src/(**/|)target(/**/*|/*|) So with quoting, it works with parentheses. Without quoting, it works with spaces. It feels as though I've tried everything, but I can't find a way to quote this so that it works for both parentheses and spaces. --089e0160b60074202805157ed48c--