From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21821 invoked by alias); 16 Apr 2016 17:10:04 -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: 21452 Received: (qmail 16154 invoked from network); 16 Apr 2016 17:10:03 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=from:message-id:date:in-reply-to:comments:references:to:subject :mime-version; bh=Fc6MwGdOtK1Iz3Nnf5ppNFFb9m6Q4jI1VFH/4xTsQMc=; b=BY1dGOc7+GnSE/Rs54JxXqRllBQPwy+vL7muUcHE4TebahxMoO7q4aRS7NSIqsGXJu 7ZKd6KglfAEsii2jzYZD/TGJ8+9X1OFn/H0ZOykU9ndn/qpQQZyMCm8i6STG3FRzpq0O tnuliYPrCD4ME6zS0uA14mEMx15UPLPA+KCt1kTZNHnPsCNfUOLn1UuntnOgHVcD8Djw sa1rA4yOjZuBugulJZF2nyEPitKBEAZG2o2vyqXYcfPochJQOvDtDQ01R8I8f+oXwoLB 3+EQJ46Wm0C/U0B7E9oUJcYtfUiW0c+VRZkmx2bJB0Jp7+pMYAelU4zM87bzsCfRVHVo p4sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:message-id:date:in-reply-to:comments :references:to:subject:mime-version; bh=Fc6MwGdOtK1Iz3Nnf5ppNFFb9m6Q4jI1VFH/4xTsQMc=; b=nNOKByXepfqSjoBlSWPQktXGF8WvLm+vCb+6t6ynpXBu5sDZhqSAppL/V1R/fjQ3cb v+t3Jczrg7y1dHd9Ckb4BAuTw7u8OvbUdK8hHnGa0pWJ5/IyEXQvrduK0mR6lu2BaxQr zqkD8d2pP/Umoq58YX24yxj052JL5fb9NmZkX7OdSV/foYgg2LzhCQlCQWHnMZt1sqn9 6+Lnhs+9+MCeo2OlVFxTOPIdoDM0I4xpbYS5RTJpoztDT+pyZz86Xn9jcg4rPpeI5Mn9 DbAWVVTXbiG09D2ilzNU0Z52BKYU+T4/2b2pR+z6XzaaHk26ArY3BFbdLzcTCLIhE1qZ oNEQ== X-Gm-Message-State: AOPr4FUPSKI+6xFIkm5OFXYqhMozrv3iTqDxby/RMvDG1LTLiwbNcA/eUyhLw6zq08xQqA== X-Received: by 10.66.231.98 with SMTP id tf2mr1487354pac.56.1460826602384; Sat, 16 Apr 2016 10:10:02 -0700 (PDT) From: Bart Schaefer Message-Id: <160416101008.ZM24340@torch.brasslantern.com> Date: Sat, 16 Apr 2016 10:10:08 -0700 In-Reply-To: <20160416113133.GA10973@solfire> Comments: In reply to Meino.Cramer@gmx.de "[[ -f ]] and filename generation" (Apr 16, 1:31pm) References: <20160416113133.GA10973@solfire> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-users@zsh.org Subject: Re: [[ -f ]] and filename generation MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On Apr 16, 1:31pm, Meino.Cramer@gmx.de wrote: } } A script I am writing is reading filenames from a list. } These filenames not complete. } } I want to check for the existing of the files in the list on disk with } a construct like this } } if [[ -f $FILEFROMLIST ]] ; then Assuming this test returns true, do you thereafter need the names of the actual files, or do you only care that some such files exist? If you will need the filenames anyway, globbing them into an array and then testing that the array is not empty is probably most efficient. If you only care that at least one such name exists, then Eric's (#qY1) solution is on the right track, but you probably want if [[ -f "$FILEFROMLIST"*(#q.NY1) ]] ; then ... to check only plain files (not directories) and to avoid "no match" errors (unless you commonly have NO_NOMATCH set). Note the wildcard is outside the double-quotes. If you want to test more complicated conditions, such as that ALL the matching names on disk are plain files, then it gets more difficult to avoid globbing them into an array and processing each name. One silly example: if test -d . "$FILEFROMLIST"*(P:-a:P:-f:N) ; then ... The (P) glob flag prepends the argument strings to each glob result as a separate word, so this produces something like test -d . -a -f filename -a -f filename.ext -a -f filename.ext1.ext2 which will fail if any of the matching names is not a plain file. But note this will NOT work with the [[ ]] syntax; globbing there cannot introduce new conditional operators.