--- Nicolas SABOURET <[EMAIL PROTECTED]> wrote: > Nicolas
SABOURET wrote:
> > 
> > if [ grep -c "cha�ne" -gt 0 ]; then ...
> > 
> 
> grep -c "chaine" nomfichier en fait, et entre ` (backquote) si c'est
> dans le "if".
> 
> Pardon d'avoir �t� approximatif.
> 

Je dirais m�me plus : �tant donn� que le fichier peut �tre tr�s gros,
il est s�rement plus indiqu� de sortir d�s qu'une occurence est
trouv�e, et non pas aller jusqu'� la fin pour compter toutes les
occurences (option -c).

Extrait du man de 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.

Donc un -q me semble plus appropri� dans le cas d'un grep conformant �
POSIX.2 (cas du grep GNU), ou -s pour un grep "traditionnel" ...

Le test se fait alors sur le code de sortie (stock� dans la variable
shell $?) :

Normally, exit status is 0 if matches were found, and 1 if
no  matches  were found.  (The -v option inverts the sense
of the exit status.)  Exit status is 2 if there were  syn-
tax  errors  in  the pattern, inaccessible input files, or
other system errors.

    Fran�ois.

=====
Francois BOTTIN
--
    "How kind," the PFY sighs. "But where will I go?" 
    "Somewhere where they know nothing about computing...
where they wouldn't know a RAM chip from a potato chip!" 
    "But I don't want to visit Microsoft!" he whines.
              The BOFH 1998 - Simon Travaglia (bofh.ntk.net)

________________________________________________________________
Nokia 5510 looks weird sounds great. 
Go to http://uk.promotions.yahoo.com/nokia/ discover and win it! 
The competition ends 16 th of December 2001.

Répondre à