From owner-freebsd-questions@FreeBSD.ORG Mon Oct 17 21:40:03 2005 Return-Path: X-Original-To: freebsd-questions@freebsd.org Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 7471716A420 for ; Mon, 17 Oct 2005 21:40:03 +0000 (GMT) (envelope-from drew@mykitchentable.net) Received: from relay01.roc.ny.frontiernet.net (relay01.roc.ny.frontiernet.net [66.133.182.164]) by mx1.FreeBSD.org (Postfix) with ESMTP id 0B47043D68 for ; Mon, 17 Oct 2005 21:39:42 +0000 (GMT) (envelope-from drew@mykitchentable.net) Received: from filter01.roc.ny.frontiernet.net (filter01.roc.ny.frontiernet.net [66.133.183.68]) by relay01.roc.ny.frontiernet.net (Postfix) with ESMTP id B341A3669A6; Mon, 17 Oct 2005 19:50:39 +0000 (UTC) Received: from relay01.roc.ny.frontiernet.net ([66.133.182.164]) by filter01.roc.ny.frontiernet.net (filter01.roc.ny.frontiernet.net [66.133.183.68]) (amavisd-new, port 10024) with LMTP id 20355-06-75; Mon, 17 Oct 2005 19:50:39 +0000 (UTC) Received: from blacklamb.mykitchentable.net (67-51-164-214.dsl1.elk.ca.frontiernet.net [67.51.164.214]) by relay01.roc.ny.frontiernet.net (Postfix) with ESMTP id C5D13367AD7; Mon, 17 Oct 2005 19:36:51 +0000 (UTC) Received: from [165.107.42.123] (unknown [165.107.42.123]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by blacklamb.mykitchentable.net (Postfix) with ESMTP id 411D51536A2; Mon, 17 Oct 2005 12:36:50 -0700 (PDT) Message-ID: <4353FCDD.2040406@mykitchentable.net> Date: Mon, 17 Oct 2005 12:34:53 -0700 From: Drew Tomlinson User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Will Maier References: <43518497.6050505@mykitchentable.net> <20051015230706.GI3253@localdomain> In-Reply-To: <20051015230706.GI3253@localdomain> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new-2.3.2 (20050629) at filter01.roc.ny.frontiernet.net Cc: freebsd-questions@freebsd.org Subject: Re: Bash Pattern Matching Syntax X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 17 Oct 2005 21:40:03 -0000 On 10/15/2005 4:07 PM Will Maier wrote: >On Sat, Oct 15, 2005 at 03:37:11PM -0700, Drew Tomlinson wrote: > > >>I want to list the files in a directory that end in ".jpg" >>irregardless of case. Thus after reading the bash man page, it >>seems I should be able to issue a command something along the >>lines of "ls [*.[JjPpGg]]" or "ls *.[JjPpGg]" but neither of >>these work and return a "No such file or directory" message. I've >>also tried various ways of escaping the '*' and '." but that >>didn't help either. However "ls *[JjPpGg]" does work by listing >>the files. However I want to match the "." before "jpg" as well. >>What is the correct syntax for what I'm trying to do? >> >> > >The square brackets define a range of characters; [a-z] includes all >lowercase alphabetic characters between 'a' and 'z' and will match >_only one character from that range_ in a given string. > > [a-z] matches 'b' > [a-z] matches 'z' > [a-z] doesn't match 'all' > [a-z] doesn't match '1' > >Your first attempt, [*.[JjPpGg]], has an extra pair of brackets. >Secondly, it (like your second attempt) defines a range that would >match only one character, JjPpGg: > > [JjPpGg] matches 'j' > [JjPpGg] matches 'G' > [JjPpGg] doesn't match 'JPG' > [JjPpGg] doesn't match 'jpg' > >You need to break your patterns up; what you're looking for is a >pattern of three characters, with 'J' or 'j' in the first position, >'P' or 'p' in the second, and 'G' or 'g' in the third. That entire >pattern should be prepended by a string of any characters (*) and a >period (.). > >Here are some examples to demonstrate what I've written above; they >conclude with a pattern that will match the files you're looking >for. > > sh-3.00$ ls > a all test.JPG test.jpg > sh-3.00$ ls [a-z] > a > sh-3.00$ ls [all] > a > sh-3.00$ ls *.[JjPpGg] > ls: *.[JjPpGg]: No such file or directory > sh-3.00$ ls *.[Jj][Pp][Gg] > test.JPG test.jpg > > Thank you very much for your explanation. Now I understand my error. :) Drew -- Visit The Alchemist's Warehouse Magic Tricks, DVDs, Videos, Books, & More! http://www.alchemistswarehouse.com