Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!psuvax1!gondor.psu.edu!flee From: flee@gondor.psu.edu (Felix Lee) Newsgroups: comp.unix.questions Subject: Re: Environment variables. And csh bogosity. Message-ID: <2885@psuvax1.psu.edu> Date: Sat, 29-Aug-87 00:07:10 EDT Article-I.D.: psuvax1.2885 Posted: Sat Aug 29 00:07:10 1987 Date-Received: Sun, 30-Aug-87 06:37:26 EDT References: <626@unmvax.unm.edu> <2876@phri.UUCP> <7173@ism780c.UUCP> Sender: netnews@psuvax1.psu.edu Reply-To: flee@gondor.psu.edu (Felix Lee) Organization: The Roadside Picnic Lines: 30 In article <7173@ism780c.UUCP> mikep@ism780c.UUCP (Michael A. Petonic) writes: >>In <626@unmvax.unm.edu> mike@turing.UNM.EDU.UUCP (Michael I. Bushnell) writes: >>> How can I determine if an environment variable is set using csh? >A better was is to use printenv and the "status" variable, like this: > printenv FOO > /dev/null > if ( $status == 1 ) then > variable is not set > else > variable is set > fi A different way is to use printenv like this: if ( { printenv FOO } ) echo Yes Unfortunately, if ( { printenv FOO >/dev/null } ) echo Yes doesn't work. Csh ignores the redirection. You have to say: if ( { ( printenv FOO >/dev/null ) } ) echo Yes Or, if you're using a block if, you can say if ( { printenv FOO } ) then >/dev/null echo Yes else echo No endif Isn't csh wonderful? Let's hear it for ad-hoc parsing. -- Felix Lee flee@gondor.psu.edu {cbosgd,cmcl2}!psuvax1!gondor!flee Copyright (C) 1987 by Felix Lee. Reprinted with permission.