Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 12 Apr 1998 22:13:17 -0500
From:      Dan Nelson <dnelson@emsphone.com>
To:        Dean Hollister <dean@odyssey.apana.org.au>, FreeBSD Questions <freebsd-questions@FreeBSD.ORG>
Subject:   Re: bash: checking for empty string?
Message-ID:  <19980412221317.A10661@emsphone.com>
In-Reply-To: <Pine.BSF.3.96.980413104954.2098A-100000@odyssey.apana.org.au>; from "Dean Hollister" on Mon Apr 13 10:50:47 GMT 1998
References:  <Pine.BSF.3.96.980413104954.2098A-100000@odyssey.apana.org.au>

next in thread | previous in thread | raw e-mail | index | archive | help
In the last episode (Apr 13), Dean Hollister said:
> Hiyall,
> 
> If have a string $name. I need to check if this is blank, and if it
> is, exit the script. Any ideas?

These will work with any bourne-shell based script; not just bash.

[ -z "$name" ] && exit

[ "$name" = "" ] && exit

if [ -z "$name" ] then
	exit
fi

Note that $name will expand to "" if $name is unset or is set to the
empty string.  To learn how to tell the difference, man sh and search
for "parameter expansion".

	-Dan "You can rule the world with /bin/sh" Nelson
	dnelson@emsphone.com

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message



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