Date: Mon, 10 Jun 2013 14:05:45 -0500 From: Tim Daneliuk <tundra@tundraware.com> To: freebsd-questions@freebsd.org Subject: Re: Bourne shell "if" syntax Message-ID: <51B62389.5000500@tundraware.com> In-Reply-To: <121701ce660c$9a9aa5b0$cfcff110$@freebsd.org> References: <51b620a6.42f.2b6a6400.5605dcf0@go2france.com> <121701ce660c$9a9aa5b0$cfcff110$@freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On 06/10/2013 01:59 PM, dteske@freebsd.org wrote: > > >> -----Original Message----- >> From: owner-freebsd-questions@freebsd.org [mailto:owner-freebsd- >> questions@freebsd.org] On Behalf Of lconrad@go2france.com >> Sent: Monday, June 10, 2013 11:53 AM >> To: freebsd-questions@freebsd.org >> Subject: Bourne shell "if" syntax >> >> >> >> script fragment: >> >> PTR=`dig @some.dns +short +norec -x a.b.c.d` >> >> echo "$PTR" >> >> if [ "$PTR" == "" ] ; then >> > > if [ "$PTR" = "" ]; then > > or > > if [ -z "$PTR" ]; then > > or > > if [ "$PTR" ]; then > > but _NOT_ > > if [ "$PTR" == "" ]; then > I work across a bunch of different OSs and shells of many vintages. As I recall, the -z argument has problems of portability on older/broken shells and/or is not available in all environments (I cannot recall which at the moment). So I achieve the same results by using a character sentinel that guarantees that the comparison always works: f [ _"$PTR" == _ ] ; then -- ----------------------------------------------------------------------- Tim Daneliuk
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?51B62389.5000500>