This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: problem with globs using curly brackets and ^


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/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]