2009-12-11, 16:16(+00), Marc Herbert: > Sven Mascheck a écrit : >> Chris F.A. Johnson wrote: >> >>> This has been discussed more than once in c.u.s; check the >>> archives. >> >> and that's why we better discuss it here now? > > I think Chris' message was more like: "let's not discuss it at all and > just read the archives" :-] > > > In case anyone is interested my winner (so far) is: > > exists() > { > [ -e "$1" -o -L "$1" ] > }
$ exists = bash: [: too many arguments [ -e "$1" ] -o [ -L "$1" ] (that one would still choke on '=' with the Bourne shell, note). > if exists foo/*; then > for f in foo/*; do > ... > done > fi [...] Also, if you have the 'r' but not 'x' permission on 'foo', the wildcard will expand, but the tests will fail. You don't need the tests, you can do: ( set -- foo/[*] foo/* case $1$2 in ("foo/[*]foo/*") echo no non-hidden files or directory not readable;; (*) echo some non-hidden files in here esac ) Or bash specific: shopt -s nullglob dotglob files=(foo/*) (( ${#fil...@]} )) zsh: files=(foo/*(ND[1])) (( $#files )) -- Stéphane