# HG changeset patch # User Alexander Eremin # Date 1333118998 14400 # Node ID 16aca17fb9a41a18db88fc1971921df91be9a149 # Parent 3a9ce5c9da15126d685d073566504246a403430a 650 grep support for -q would be useful Reviewed by: David Höppner <0xffea@googlemail.com> Reviewed by: Dan McDonald Reviewed by: Andrew Stormont Reviewed by: Garrett D'Amore Reviewed by: Albert Lee Approved by: Albert Lee diff -r 3a9ce5c9da15 -r 16aca17fb9a4 usr/src/cmd/grep/grep.c --- a/usr/src/cmd/grep/grep.c Fri Mar 30 05:41:25 2012 -0700 +++ b/usr/src/cmd/grep/grep.c Fri Mar 30 10:49:58 2012 -0400 @@ -30,7 +30,7 @@ /* Copyright (c) 1987, 1988 Microsoft Corporation */ /* All Rights Reserved */ -#pragma ident "%Z%%M% %I% %E% SMI" +/* Copyright 2012 Nexenta Systems, Inc. All rights reserved. */ /* * grep -- print lines matching (or not matching) a pattern @@ -88,6 +88,7 @@ static int iflag; static int wflag; static int hflag; +static int qflag; static int errflg; static int nfile; static long long tln; @@ -113,11 +114,14 @@ #endif (void) textdomain(TEXT_DOMAIN); - while ((c = getopt(argc, argv, "hblcnsviyw")) != -1) + while ((c = getopt(argc, argv, "hqblcnsviyw")) != -1) switch (c) { case 'h': hflag++; break; + case 'q': /* POSIX: quiet: status only */ + qflag++; + break; case 'v': vflag++; break; @@ -148,7 +152,7 @@ } if (errflg || (optind >= argc)) { - errmsg("Usage: grep -hblcnsviw pattern file . . .\n", + errmsg("Usage: grep [-c|-l|-q] -hbnsviw pattern file . . .\n", (char *)NULL); exit(2); } @@ -228,7 +232,7 @@ if ((count = read(temp, prntbuf, GBUFSIZ)) <= 0) { (void) close(temp); - if (cflag) { + if (cflag && !qflag) { if (nfile > 1 && !hflag && file) (void) fprintf(stdout, "%s:", file); (void) fprintf(stdout, "%lld\n", tln); @@ -324,7 +328,7 @@ } (void) close(temp); - if (cflag) { + if (cflag && !qflag) { if (nfile > 1 && !hflag && file) (void) fprintf(stdout, "%s:", file); (void) fprintf(stdout, "%lld\n", tln); @@ -340,6 +344,11 @@ if (f == NULL) f = ""; + if (qflag) { + /* no need to continue */ + return (1); + } + if (cflag) { tln++; return (0); diff -r 3a9ce5c9da15 -r 16aca17fb9a4 usr/src/man/man1/grep.1 --- a/usr/src/man/man1/grep.1 Fri Mar 30 05:41:25 2012 -0700 +++ b/usr/src/man/man1/grep.1 Fri Mar 30 10:49:58 2012 -0400 @@ -1,4 +1,5 @@ '\" te +.\" Copyright 2012 Nexenta Systems, Inc. All rights reserved. .\" Copyright 1989 AT&T .\" Copyright (c) 2008, Sun Microsystems, Inc. All Rights Reserved .\" Portions Copyright (c) 1992, X/Open Company Limited All Rights Reserved @@ -15,7 +16,7 @@ .SH SYNOPSIS .LP .nf -\fB/usr/bin/grep\fR [\fB-bchilnsvw\fR] \fIlimited-regular-expression\fR +\fB/usr/bin/grep\fR [\fB-c\fR | \fB-l\fR | \fB-q\fR] [\fB-bhinsvw\fR] \fIlimited-regular-expression\fR [\fIfilename\fR]... .fi @@ -134,6 +135,16 @@ .sp .ne 2 .na +\fB\fB-q\fR\fR +.ad +.RS 6n +Quiet. Does not write anything to the standard output, regardless of matching +lines. Exits with zero status if an input line is selected. +.RE + +.sp +.ne 2 +.na \fB\fB-s\fR\fR .ad .RS 6n @@ -246,16 +257,6 @@ .sp .ne 2 .na -\fB\fB-q\fR\fR -.ad -.RS 19n -Quiet. Does not write anything to the standard output, regardless of matching -lines. Exits with zero status if an input line is selected. -.RE - -.sp -.ne 2 -.na \fB\fB-x\fR\fR .ad .RS 19n