Operating System - HP-UX
1821051 Members
2678 Online
109631 Solutions
New Discussion юеВ

Re: How to check the existence of an environment variable

 
SOLVED
Go to solution
Reggie Chang
Frequent Advisor

How to check the existence of an environment variable

Hi there,

Is there a way to check the existence of an
environment variable?

Something like if ( $CheckThis == "" ) then
in C-Shell would not work. Is getenv an option?
That does not seem to be a standard UNIX command.

Your help is very much appreciated.

Reggie
5 REPLIES 5
Sanjay_6
Honored Contributor
Solution

Re: How to check the existence of an environment variable

Hi

"env" is a standard unix command to get env variables.

type env at the prompt and it gives you a list of all env variables currently set.

Hope this helps.

Regds
RAC_1
Honored Contributor

Re: How to check the existence of an environment variable

on KSH/sh-posix, the command is set -u

When set -u is doen, script will error ou when undefined variables are accessed.

There should be something similar on csh.

Anil
There is no substitute to HARDWORK
Mark Greene_1
Honored Contributor

Re: How to check the existence of an environment variable

See the man page for printenv which should work in csh.

mark
the future will be a lot like now, only later
Reggie Chang
Frequent Advisor

Re: How to check the existence of an environment variable

Sanjay and RAC,

Thank you for the info.

I use "if ( `env | grep -c CheckMe` == 1 ) then"
in #!/bin/csh and it works fine.

Reggie
Reggie Chang
Frequent Advisor

Re: How to check the existence of an environment variable

The solution has been found.