From owner-freebsd-questions@freebsd.org Wed Feb 10 13:20:21 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 2B7ABAA328A for ; Wed, 10 Feb 2016 13:20:21 +0000 (UTC) (envelope-from m.seaman@infracaninophile.co.uk) Received: from smtp.infracaninophile.co.uk (smtp.infracaninophile.co.uk [IPv6:2001:8b0:151:1:c4ea:bd49:619b:6cb3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id AEFB41B65 for ; Wed, 10 Feb 2016 13:20:20 +0000 (UTC) (envelope-from m.seaman@infracaninophile.co.uk) Received: from zero-gravitas.local (unknown [85.199.232.226]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: m.seaman@infracaninophile.co.uk) by smtp.infracaninophile.co.uk (Postfix) with ESMTPSA id 456C4CC49 for ; Wed, 10 Feb 2016 13:20:15 +0000 (UTC) Authentication-Results: smtp.infracaninophile.co.uk; dmarc=none header.from=infracaninophile.co.uk DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=infracaninophile.co.uk; s=201601-infracaninophile; t=1455110415; bh=KLS5LeCf6TkPhtabg27e+0FZrn8eeLfru+rPjpycouQ=; h=Subject:To:References:From:Date:In-Reply-To; z=Subject:=20Re:=20/bin/sh=20starts=20with=20check=20in=20script|To :=20freebsd-questions@freebsd.org|References:=20<56BB33E8.4080900@ gmail.com>|From:=20Matthew=20Seaman=20|Date:=20Wed,=2010=20Feb=202016=2013:20:09=20+0000|In-Reply-T o:=20<56BB33E8.4080900@gmail.com>; b=kXuE4jN3D/m06WiW116HskmHD8pBzlk1fATTSq+b4fhdj3bbJoxkLC4lkkSuGXqDe XcwVCak/o0A3EaGItY4VEv7v69cWrZGZsFjlQTBpWNCWbrNL4+zwlhpUwtK26QDKFl KijQSIdNKLKhue9s0xSqY/YnM1qNKatwXgMJzsf8= Subject: Re: /bin/sh starts with check in script To: freebsd-questions@freebsd.org References: <56BB33E8.4080900@gmail.com> From: Matthew Seaman Message-ID: <56BB3909.3070505@infracaninophile.co.uk> Date: Wed, 10 Feb 2016 13:20:09 +0000 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 In-Reply-To: <56BB33E8.4080900@gmail.com> Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="T8h17TGlTpdMaqVEPqKs5GIx6bj9dHfTv" X-Virus-Scanned: clamav-milter 0.99 at smtp.infracaninophile.co.uk X-Virus-Status: Clean X-Spam-Status: No, score=2.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, RDNS_NONE, SPF_FAIL autolearn=no autolearn_force=no version=3.4.1 X-Spam-Level: ** X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on smtp.infracaninophile.co.uk 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 13:20:21 -0000 This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --T8h17TGlTpdMaqVEPqKs5GIx6bj9dHfTv Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable On 2016/02/10 12:58, Sergei G wrote: > 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 configuratio= n > file. >=20 > #!/bin/sh > if expr "${line}" : '#.*' > /dev/null; then > echo Ignoring comment line > fi >=20 > I had to redirect to /dev/null, because expr prints a number to STDOUT.= =20 > Is there a better way to do this kind of string matching check in > /bin/sh (not bash)? When you say 'in /bin/sh' I take it you mean without calling any external programs? Otherwise the natural way would be to use grep(1). Try: #!/bin/sh case ${line} in "#*") echo Ignoring comment line ;; *) ... do whatever ... ;; esac Cheers, Matthew --T8h17TGlTpdMaqVEPqKs5GIx6bj9dHfTv Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Comment: GPGTools - https://gpgtools.org iQJ8BAEBCgBmBQJWuzkOXxSAAAAAAC4AKGlzc3Vlci1mcHJAbm90YXRpb25zLm9w ZW5wZ3AuZmlmdGhob3JzZW1hbi5uZXQxOUYxNTRFQ0JGMTEyRTUwNTQ0RTNGMzAw MDUxM0YxMEUwQTlFNEU3AAoJEABRPxDgqeTntdAP/j/2irzlDKBMz8X9Jg/tg4jS yaiyIMscUhZlD9aTe35EnFZy1LT+QIBQZcR70wZOuqB0iN9fdS7Mr3bnqj3eMnvq bpcETIebmlkCuJPXe8DOzCY7LDWiE3iWNnUG+8gLYSee9R4rum97gNZJpwnbxsqK /RrP5gTtBmx1Xodj+edvr//Td8VtBkkw602x10LFGZ9/Qb7bABFSHj08MilmraS1 7vIMBS3Q9zQAMW1Xzblxg7mCqe8DleoLXfTEul6tP8/WtgMIwz2RT+RNWZn9KneY PTSrOFuDf32NULh5r8a8+7ne9qzFoT5+9A34Ovbu74+Gb0tAVZF1SbHREYOHXWV4 ou3Pd9XFgNoUt0lJQIk/3y4PtsUYFh8Z2LD/PI9Nn9XtBbO42IW6OVzUUHKr93ng KcaJsWFpJ+euRZHR+PsE/fJVHNrOZbqkACV1mn7xLvXSs52nE/VOVSWmpwG/lFA/ Nk/EJlpA4+Mhya8S+Ui3u26PP4qdW35zAM/rNtoJeNGNgQ3dzjmgwEFq0fvLYtXm zrw27DdDFyf8/fC6GcxUAPK1TogifWfEwSDOJAyYdUlz4LPGxOZquCX5yh0jF0yy eaWRAKD0UnSzLsHzeRcOaqX9EtT90yBdcC5C45aUCU+SBMkBV4qHytKIKfbJYN86 NNqRiShsi0Sh9KlIk2ua =57Wv -----END PGP SIGNATURE----- --T8h17TGlTpdMaqVEPqKs5GIx6bj9dHfTv--