gnu-arch-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnu-arch-users] shell globbing (was Re: Beginner help request)


From: Adam Spiers
Subject: [Gnu-arch-users] shell globbing (was Re: Beginner help request)
Date: Sun, 11 Jan 2004 10:58:15 +0000
User-agent: Mutt/1.4.1i

Tom Lord (address@hidden) wrote:
> > From: Dustin Sallings <address@hidden>
> 
> > On Jan 10, 2004, at 15:52, Tom Lord wrote:
> 
> > > Typically, if there are no files matching *.php, then the shell will
> > > expand that to "*.php".  I'm not sure off the top of my head if that
> > > is standard posix behavior for a shell (I think it is but wouldn't
> > > swear to it) -- I'd suggest looking for the sh spec on something like
> > > the opengroup web site if you are curious.
> 
> >     tcsh produces an error when all globs on a commandline fail to expand 
> > to anything.  It seems to be a good interactive behavior.
> 
> Oh, I agree with that.   Not just interactive -- I can't see any
> circumstance in which I'd really _want_ anything different.   My guess
> would be that, sadly, the "'*.foo' with no matching files expands to
> *.foo" behavior was originally intended as a _feature_ for interactive
> use.   Isn't that weird?
> 
> "Those guys" got a lot right -- but a lot wrong, too.

Yeah.  FYI:

    pdksh% echo *.nothere
    *.nothere
    pdksh% echo $?
    0

Broken and apparently unfixable.

    bash-2.05b$ echo *.nothere
    *.nothere
    bash-2.05b$ echo $?
    0
    bash-2.05b$ shopt -s nullglob
    bash-2.05b$ echo *.nothere

    bash-2.05b$ echo $?
    0

Broken but fixable.

    tcsh% echo *.nothere
    echo: No match.
    tcsh% echo $?
    1
    tcsh% set nonomatch
    tcsh% echo *.nothere
    *.nothere
    tcsh% echo $?
    0

Not broken unless you really want it to be.

    zsh% echo *.nothere
    zsh: no matches found: *.nothere
    zsh% echo $?
    1
    zsh% echo *.nothere(N)

    zsh% echo $?
    0
    zsh% setopt nullglob
    zsh% echo *.nothere

    zsh% echo $?
    0
    zsh% unsetopt nullglob 
    zsh% unsetopt nomatch
    zsh% echo *.nothere
    *.nothere
    zsh% echo $?
    0

Ditto, but also has the option of expanding to nothing which is
sometimes what you want:

    for file in foo bar* baz; do
        ...

Finally a bit of useless trivia:

For those who thought that tcsh's choice of option name being
`nonomatch' was rather odd (and presumably there for historical
reasons relating to an earlier `nomatch' option?) , it is mildly
interesting to note that in zsh, since `unsetopt FOO' is equivalent to
`setopt noFOO', `setopt nonomatch' will achieve the same thing.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]