[ale] I need a bash clue.

Fletch fletch at phydeaux.org
Thu May 13 23:57:00 EDT 2004


>>>>> "Joe" == Joe Knapka <jknapka at kneuro.net> writes:

[...]

    >> for i in **/*(/); do (cd $i; [[ -n "$(print *.c(N))" ]] &&etags
    >> *.c) ; done

    Joe> Looks interesting, though no less opaque than the bash
    Joe> version.  I'll read up on zsh.

Pretty much the same as the bash version, but to elaborate on a couple
of the zsh-isms:


**/*(/) -- '**' is a shorthand for (*/)# which means match zero or
           more directory names; "*" the same as any other shell, and
           "(/)" means limit to just directories; so this expands to
           the name of every directory under .

*.c(N)
        -- This expands to all files matching *.c, but the (N)
           modifier says don't gripe if there's no matches (it just
           disappears from the command line)


[[ -n "$(print *.c(N))" ]]
        -- This uses a subshell to make a string of the names of any
           .c files in the current directory; if there's none it'll
           be a zero length string, and the -n test (non-zero length
           string) will fail


Actually that last bit's not really strictly a zsh-ism, as you could
do something similar with bash like


[[ "$( echo *.c )" != "*.c" ]] && etags *.c


since it'll leave the glob unchanged if there's no matches (rather
than the csh-y way zsh complains).


And really it could be done without $()/`` in zsh by setting an array
a=(*.c(N)) and then testing [[ -n "$a" ]] instead.


But I'm going to stop piddling with it now. :)

-- 
Fletch                | "If you find my answers frightening,       __`'/|
fletch at phydeaux.org   |  Vincent, you should cease askin'          \ o.O'
                      |  scary questions." -- Jules                =(___)=
                      |                                               U



More information about the Ale mailing list