Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!rutgers!cmcl2!adm!smoke!gwyn From: gwyn@smoke.BRL.MIL (Doug Gwyn ) Newsgroups: comp.unix.questions Subject: Re: Bourne Shell: Variable defined? Keywords: Bourne shell, elementary question Message-ID: <9899@smoke.BRL.MIL> Date: 22 Mar 89 04:38:30 GMT References: <1819@umbc3.UMBC.EDU> Reply-To: gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 18 In article <1819@umbc3.UMBC.EDU> rostamia@umbc3.UMBC.EDU (Rouben Rostamian) writes: >In C Shell the variable $?foo returns true or false (0 of 1, really) >depending on whether or not the variable "foo" has been already defined. >What is the equivalent construction in Bourne Shell? In other words, >how can I tell, in Bourne Shell, whether the variable "foo" exits. Usually all you need is if [ X"$foo" = X ] then : # doesn't exist or is an empty string else : # exists as a nonempty string fi The X is to avoid problems if $foo starts with a dash etc. If that's not a problem then if [ "$foo" ] then : # nonempty else : # empty or nonexistent fi is a simpler test.