Am Mon, 2002-08-05 um 02.01 schrieb Jan Trippler:
On Son, 04 Aug 2002 at 22:10 (+0200), Adalbert Michelic wrote: [...]
Warum nicht so?
ps aux | grep -q [j]ava && export running=TRUE || export running=FALSE
Diese ... && ... || ... Geschichte habe ich mir ehrlich gesagt abgewöhnt, weil ich ein paar Mal mit Nebeneffekten gekämpft habe. Wirf mal einen Blick in das "Shellology" Kapitel in autoconf.info eines autoconf >= 2.50. Es gibt dort einen eigenen Abschnitt zu diesem Thema.
BTW: grep -q ist ebenfalls eine äusserst fragwürdige Angelegenheit. Aus man grep: -q, --quiet, --silent Quiet; suppress normal output. The scanning will stop on the first match. Also see the -s or --no-messages option below. [..] -s, --no-messages Suppress error messages about nonexistent or unreadable files. Portability note: unlike GNU grep, traditional grep did not conform to POSIX.2, because traditional grep lacked a -q option and its -s option behaved like GNU grep's -q option. Shell scripts intended to be portable to traditional grep should avoid both -q and -s and should redirect output to /dev/null instead.
Tausch mal die Reihenfolge aus, und Du erlebst Dein blaues Wunder: ls nicht_existierende_datei || echo nicht da && echo ist da Nimm test und if/then/else/fi .. ist deutlich zuverlässiger ;)
Was ich wieder nicht verstehe: wieso kann man mit [] verhindern, dass grep selbst ein true liefert? Würde mich auch interessieren - Ich tippe auf Bug.
Ralf