help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] How to tell if an environment variable exists or not


From: Stephane Chazelas
Subject: Re: [Help-bash] How to tell if an environment variable exists or not
Date: Tue, 6 Mar 2012 17:01:05 +0000
User-agent: Mutt/1.5.21 (2010-09-15)

2012-03-05 14:57:44 -0500, Greg Wooledge:
> On Mon, Mar 05, 2012 at 11:17:35AM -0600, Bill Gradwohl wrote:
> > Assuming set -u, how does one test to see if an environment variable exists
> > without creating it in the process?
> 
> if [[ ${foo+defined} ]]
[...]

Though that answer is probably what the OP was looking for,
please note that it will not differenciate between environment
variables and other shell variables.

Also, this will only work for environment variables that can be
mapped to shell variables and are not masqued by builtin shell
variables (like *, 1...), some are being unexported or altered
by bash anyway.

-- 
Stephane




reply via email to

[Prev in Thread] Current Thread [Next in Thread]