From owner-freebsd-questions@freebsd.org Wed Feb 10 12:58:19 2016 Return-Path: Delivered-To: freebsd-questions@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id DEFA0AA26F4 for ; Wed, 10 Feb 2016 12:58:19 +0000 (UTC) (envelope-from sergeig.public@gmail.com) Received: from mail-pf0-x231.google.com (mail-pf0-x231.google.com [IPv6:2607:f8b0:400e:c00::231]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id AF057CA3 for ; Wed, 10 Feb 2016 12:58:19 +0000 (UTC) (envelope-from sergeig.public@gmail.com) Received: by mail-pf0-x231.google.com with SMTP id x65so11817618pfb.1 for ; Wed, 10 Feb 2016 04:58:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=to:from:subject:message-id:date:user-agent:mime-version :content-type:content-transfer-encoding; bh=o9IFCPBCaFJbr6o9aMbdQ1fnG5d1k+wwevCbNIxdSno=; b=EdFlFi4X9Le1V4hfrqenvvCQFAPDlyEorckR1/fvYy73DFhJanbhH2e03kcwGA0SBO DQargFZyRfa/qfkiow0orQmnJ27jv76ghLpZuek9uEI8QK0CB5TZ5r8zQD0DFkPViyIC 2ZxMrZ3fFyj4VPxYoPY8IAG5TRxYexmWCnOYh5l1/cnop8zitrHSgsqbtt2LZ7xo1cYs h0E8+OrUF8GB1kRr0uO1r+MqKPOCtSTQyyXMLaOCSUID6FXRDNzUqFYmzy6xgOMNyfK5 jlXhtkoIfeZT/7Avqp2wg/7y2EagYo+IZXfCxwPPOvdQp9VlSB8zAc/lVTg3UibqHQSY 7A3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-type:content-transfer-encoding; bh=o9IFCPBCaFJbr6o9aMbdQ1fnG5d1k+wwevCbNIxdSno=; b=YhZt7Py/xXbvhX34JolgSmhlNrwHPynK5cuTLNA6pTsTapKeQQxlftdqN6TaHwfhqS 7SO6NdD8xquzFK68EGFt+MzlBdjmnGv0USC4qzXdTHhgcXqvlEg3Df+NgUwQeG4CGgF5 X0PVYOQ57TuEZF62ZRAQxvDJDJ+UOU4ozafSJHeGuOPf2EiSRkpwNb1FstcmSp2hgWBQ HsV2tDbLsM2TmW7QCgD11+WE2sBHjP340GdnnwjI93Ufgzw+F+a/fUpsT3LRUkUybE8u DGqXzX6pUiv/qQHmMlCkNBU1JKO8KDSEOrNSdsZeMWu5gY8Y2iaGUVZZ4W56uYA7C+Oq 86CA== X-Gm-Message-State: AG10YOSr8sbgiogOa9+A6qo9W9iQ+SQpgf+Scr2sSQrjb8pyX5BQTBxVU8oUmPG943PT2g== X-Received: by 10.98.32.5 with SMTP id g5mr58496428pfg.74.1455109099281; Wed, 10 Feb 2016 04:58:19 -0800 (PST) Received: from SergeiMBP.local (c-24-16-122-177.hsd1.wa.comcast.net. [24.16.122.177]) by smtp.googlemail.com with ESMTPSA id yx4sm5211536pac.5.2016.02.10.04.58.18 for (version=TLSv1/SSLv3 cipher=OTHER); Wed, 10 Feb 2016 04:58:18 -0800 (PST) To: FreeBSD Questions From: Sergei G Subject: /bin/sh starts with check in script Message-ID: <56BB33E8.4080900@gmail.com> Date: Wed, 10 Feb 2016 04:58:16 -0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 10 Feb 2016 12:58:20 -0000 I came up with this solution to check if variable $line starts with a hash. Basically I am checking if line is a comment in the configuration file. #!/bin/sh if expr "${line}" : '#.*' > /dev/null; then echo Ignoring comment line fi I had to redirect to /dev/null, because expr prints a number to STDOUT. Is there a better way to do this kind of string matching check in /bin/sh (not bash)? Thanks