Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 10 Feb 2016 13:20:09 +0000
From:      Matthew Seaman <m.seaman@infracaninophile.co.uk>
To:        freebsd-questions@freebsd.org
Subject:   Re: /bin/sh starts with check in script
Message-ID:  <56BB3909.3070505@infracaninophile.co.uk>
In-Reply-To: <56BB33E8.4080900@gmail.com>
References:  <56BB33E8.4080900@gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?56BB3909.3070505>