[prev] [thread] [next] [lurker] [Date index for 2005/09/30]
David King writes: > > shopt -s nullglob > > At least in a vaguely contemporary bash. >=20 > This, of course, results in commands responding as if you typed nothing > where a wildcard doesn't match. So=20 > ls -l *.o > results in a directory listing instead of a slightly more helpful > ls: *.o: No such file or directory >=20 > Or > cat *.c|grep func_name > waiting on stdin for you. Which is probably worse than the wildcard crap > lying around. Yes. nullglob is useful in for loops in scripts, but I think harmful everywhere else. [Must... resist... urge... to... mention... UUOC...] > zsh has a "setopt NOMATCH" which prevents the command from running at all= in > this case: > cat *.c|grep func_name > zsh: no matches found: *.c I think that's default behaviour in csh and derivatives (but I've never sullied myself by using such hateful beasts, so I wouldn't know). > but this has the annoying effect of > find src -name *.h > never working like you want Meh. Quote the pattern if you didn't mean it to be a glob. I'd probably use such an option interactively if bash had it. Apart =66rom with "-?", that is. I can barely imagine the degree of pain and suffering that would be caused by the utter hatefulness of "foo -?" not showing me a usage message for foo. > ls *.c *.h *.o > fails unless you have all three. And if I knew what was there, I > wouldn't be listing for them. In this instance, you can do ls *.[cho] instead. Or if the extensions have more than a single character, bash lets you do this: shopt -s extglob # highly recommended anyway ls *.@(c|cc|cpp|h|o) --=20 Aaron Crane
Generated at 16:00 on 04 Oct 2005 by mariachi 0.52