delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2007/04/19/10:30:53

X-Spam-Check-By: sourceware.org
To: cygwin AT cygwin DOT com
From: Eric Blake <ebb9 AT byu DOT net>
Subject: Re: problem with globs using curly brackets and ^
Date: Thu, 19 Apr 2007 14:30:08 +0000 (UTC)
Lines: 72
Message-ID: <loom.20070419T162153-295@post.gmane.org>
References: <Pine DOT LNX DOT 4 DOT 61 DOT 0704191531570 DOT 3988 AT ask DOT diku DOT dk>
Mime-Version: 1.0
User-Agent: Loom/3.14 (http://gmane.org/)
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

Jens Rasmussen <jsrm <at> diku.dk> writes:

> I'm having a problem with globs using curly brackets and ^.
> I've searched the web+forum with no luck, so I'm sorry if an answer 
> aleardy exists.

I'm not sure what your problem is.  You have to tell us what you were trying to 
accomplish, and the output you expected, rather than just telling us that what 
happened was wrong.  Everything you listed is behaving as documented, such as 
in 'man bash'.

> $ ls -d {Desk*,doc*}
> Desktop.ini  doc

Bash expands this in two steps, first doing brace expansion to
ls -d Desk* doc*
then doing globbing to
ls -d Desktop.ini doc

> 
> BUT: (I assume that the following is because it normally makes no sense)
> 
> $ ls -d {Desk*}

Bash refuses to do brace expansion if there is no unquoted , between the {}, in 
which case it does not strip the {}.  So bash then tries to glob "{Desk*}", and 
since there are no files that match that pattern and since you don't have the 
nullglob shopt turned on, bash then invokes ls as though by

ls -d "{Desk*}"

> ls: cannot access {Desk*}: No such file or directory

and ls repeats the same thing that bash globbing discovered - there are no 
files in your current directory that match the glob pattern {Desk*}.

> 
> AND: (my actual problem)
> 
> $ ls ^doc
> ls: cannot access ^doc: No such file or directory

^ is not a globbing character, and except on ancient shells (think 
Solaris /bin/sh) where it is a synonym for |, you are asking ls to find the 
file named "^doc" which does not exist.

> 
> $ ls -d ^{Desk*,doc*}

Bash brace expansion is invoked here, leaving:

ls -d ^Desk* ^doc*

followed by bash globbing (you have no files that match ^Desk* or ^doc*), so 
bash invokes ls as if by

ls -d "^Desk*" "^doc*"

> ls: cannot access ^Desk*: No such file or directory
> ls: cannot access ^doc*: No such file or directory

and once again, ls tells you what you did.

> 
> - And yes, I'm a Linux/UNIX/Cygwin newb!

And none of this post was cygwin-specific.

-- 
Eric Blake
volunteer cygwin bash maintainer



--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019