From owner-freebsd-questions@FreeBSD.ORG Wed Jun 27 14:25:48 2012 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id E1AFA106566C for ; Wed, 27 Jun 2012 14:25:47 +0000 (UTC) (envelope-from alexmiroslav@gmail.com) Received: from mail-ob0-f182.google.com (mail-ob0-f182.google.com [209.85.214.182]) by mx1.freebsd.org (Postfix) with ESMTP id AAB2F8FC08 for ; Wed, 27 Jun 2012 14:25:47 +0000 (UTC) Received: by obbun3 with SMTP id un3so2015017obb.13 for ; Wed, 27 Jun 2012 07:25:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=yT0yzKBLI8mn9wfwrxENDsD5PPak78wv3Gk7lAdFRK0=; b=wVz1VY1kyNVQHTS14zY9r4szH110mk+SfHdkv/RHa3qSv6TZ3BBImXO2RVN0pUsH5e jY7veqCrDDDqRlgABpfyLYa/FCwmXs9w66LbpdwrbqVDb4CrPi/FGR3TrB8zG1fxYdXp 6v6zKm4adiSxyP3lzGpoAh9s420UGCO8XBtQM6beT7dhCzyzhotz2BeBtbE5LP1P+ru6 X8cJq8fiEuhDxHt58EoZY7ugs4lUwtI6U9/m5kokU09huOsldMp1GXNQhYdXMWFoqdQC 6YJmpgvJGB2TyxYGJ+bY6WoA7a4jLEPT/H1uDJ6yblsdasYzc5GceAu7hTOjAM7H82ZE umLw== MIME-Version: 1.0 Received: by 10.182.110.10 with SMTP id hw10mr20752680obb.61.1340807147091; Wed, 27 Jun 2012 07:25:47 -0700 (PDT) Received: by 10.60.143.104 with HTTP; Wed, 27 Jun 2012 07:25:46 -0700 (PDT) Date: Wed, 27 Jun 2012 10:25:46 -0400 Message-ID: From: Aleksandr Miroslav To: freebsd-questions@freebsd.org Content-Type: text/plain; charset=ISO-8859-1 Subject: shell scripting: grepping multiple patterns, logically ANDed X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 27 Jun 2012 14:25:48 -0000 hello, I'm not sure if this is the right forum for this question, but here goes. I have the following in a shell script: #!/bin/sh if [ "$#" -eq "0" ]; then find /foo fi if [ "$#" -eq "1" ]; then find /foo | grep -i $1 fi if [ "$#" -eq "2" ]; then find /foo | grep -i $1 | grep -i $2 fi if [ "$#" -eq "3" ]; then find /foo | grep -i $1 | grep -i $2 | grep -i $3 fi Is there an easier/shorter way to do this? If there are 15 arguments supplied on the command line, I don't necessarily want to build 15 if statements. Thanks in advance for your answers.