flee@gondor.psu.edu (Felix Lee) (08/29/87)
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.