This is the mail archive of the cygwin@cygwin.com 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: bash expansion question


Lynn,

[ This is almost entirely a non-Cygwin issue. ]

You have the option of telling BASH to treat a glob pattern such as *.pl 
that matches no files to yield an empty string ("shopt -s nullglob") or the 
pattern itself ("shopt -u nullglob"). The default, as you now know, is to 
have "nullglob" unset (disabled).

I believe csh / tcsh has an option to treat non-matching glob patterns as 
an error, but I see nothing in the BASH documentation suggesting that's a 
possibility for that shell.

If you put a glob pattern within either hard (single) or soft (double) 
quotes, you will inhibit any interpretation / expansion / special treatment 
of the pattern. The primary difference between hard and soft quotes is in 
the expansion of variables, $( ... ) or ` ... ` command substitutions 
occurs within double quotes but not within single quotes.

As long as you're not mixing Windows and Cygwin commands or crossing 
between Windows and Cygwin boundaries, the expansion of shell glob patterns 
always happens in the invoking shell, not in the command that is invoked. 
That's true regardless of whether the command invoked is a binary or a 
shell script. Thus, the choice of which (if any) quote marks are used 
within the invoked script is irrelevant to the globbing. However, if the 
result of the glob expansion is a file name with special characters or 
spaces in it, then the choice of quoting style, if any, will matter, since 
the expanded file name is just another string to the invoked script.

If you use CMD.exe to invoke a Cygwin program, then the glob expansion 
happens within the invoked command. See the Cygwin user docs and FAQ for 
details.

Good luck.

Randall Schulz
Mountain View, CA USA


At 09:16 2002-03-11, Lynn Wilson wrote:
>The man page for bash says: Enclosing  characters  in single quotes 
>preserves the lit- eral value of each character within the 
>quotes.  A  single quote  may not occur between single quotes, even when 
>pre- ceded by a backslash.
>
>If I write the following bash script( test.bash ):
>#!/usr/bin/bash
>echo Argument is $1
>
>If I execute this script in a directory that does NOT constain any perl 
>(*.pl) files:
>
>test.bash '*.pl'
>I get as expected:  Argument is *.pl
>
>However if there IS a perl file present I get:
>Argument is filename.pl
>
>BTW, I get exactly the same behavior if I use double quotes. Am I missing 
>something here?  I need to pass a literal pattern that may contain 
>wildcard characters into a bash script and not have the shell expandit.
>
>Thanks.
>Lynn


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.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]