From owner-freebsd-questions@FreeBSD.ORG Sat Oct 15 23:07:06 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 A63E716A41F for ; Sat, 15 Oct 2005 23:07:06 +0000 (GMT) (envelope-from willmaier@ml1.net) Received: from out3.smtp.messagingengine.com (out3.smtp.messagingengine.com [66.111.4.27]) by mx1.FreeBSD.org (Postfix) with ESMTP id DF6DF43D48 for ; Sat, 15 Oct 2005 23:07:05 +0000 (GMT) (envelope-from willmaier@ml1.net) Received: from frontend1.internal (mysql-sessions.internal [10.202.2.149]) by frontend1.messagingengine.com (Postfix) with ESMTP id AD434CD432D for ; Sat, 15 Oct 2005 19:07:03 -0400 (EDT) Received: from frontend2.messagingengine.com ([10.202.2.151]) by frontend1.internal (MEProxy); Sat, 15 Oct 2005 19:07:03 -0400 X-Sasl-enc: mZbBzFq9zydpke/o3uWAIQ3MDrfkJVJ5xEENG+6wIIHR 1129417622 Received: from merkur (host-66-202-74-42.choiceone.net [66.202.74.42]) by frontend2.messagingengine.com (Postfix) with ESMTP id 837ED570394 for ; Sat, 15 Oct 2005 19:07:02 -0400 (EDT) Received: by merkur (nbSMTP-1.00) for uid 1000 willmaier@ml1.net; Sat, 15 Oct 2005 18:07:07 -0500 (CDT) Date: Sat, 15 Oct 2005 18:07:06 -0500 From: Will Maier To: freebsd-questions@freebsd.org Message-ID: <20051015230706.GI3253@localdomain> Mail-Followup-To: freebsd-questions@freebsd.org References: <43518497.6050505@mykitchentable.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <43518497.6050505@mykitchentable.net> User-Agent: Mutt/1.5.6+20040907i 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: Sat, 15 Oct 2005 23:07:06 -0000 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 -- o--------------------------{ Will Maier }--------------------------o | jabber:..wcmaier@jabber.ccc.de | email:..........wcmaier@ml1.net | | \.........wcmaier@cae.wisc.edu | \..........wcmaier@cae.wisc.edu | *------------------[ BSD Unix: Live Free or Die ]------------------*