Am Mon, 2002-08-05 um 19.56 schrieb Jan Trippler:
On Mon, 05 Aug 2002 at 08:16 (+0200), Ralf Corsepius wrote:
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.
Da ja nicht die Ausgabe interessiert, ist es in diesem Fall sogar gut, wenn grep nach dem ersten Treffer aufhört. Sprich: grep soll nur feststellen, _dass_ mind. 1 java-Prozess existiert.
[..] -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.
Das spielt in dieser Konstruktion keine Rolle. grep liest nicht aus einer Datei, sondern von stdin, also ist mir die Fehlermeldung über nicht vorhandene Dateien wurscht.
Es geht um -q Lange Rede, kurzer Sinn -q ist nicht portabel. statt "grep -q pattern" besser "grep pattern >/dev/null" => Dein Script funktioniert auf vielen Systemen nicht. z.B.: SunOS4: SYNOPSIS grep [ -bchilnsvw ] [ -e expression ] [ filename... ] z.B. Solaris2.7: SYNOPSIS /usr/bin/grep [ -bchilnsvw ] limited-regular-expression [ filename ... ] /usr/xpg4/bin/grep [-E | -F ] [-c | -l | -q ] [ -bhinsvwx ] -e pattern_list ... [ -f pattern_file ... ] [ file ... ] Ralf