Skip to main content
Formatted code
Source Link
fra-san
  • 10.8k
  • 2
  • 27
  • 45

I want to know if a particular environment variable is set or not, from the command line. I need to distinguish between it being set to a blank string (or just whitespace) and not set at all, so I'd like to get a definitive True/False or Yes/No, not just printing nothing if it's not set.

I know that in a script, I can use "-z"-z, but I'm not sure if/how I can do it directly from the command line.

I tried this: $ echo -z "${MY_URDSFDFS}"

$ echo -z "${MY_URDSFDFS}"

But it just prints: -z

-z

I want to know if a particular environment variable is set or not, from the command line. I need to distinguish between it being set to a blank string (or just whitespace) and not set at all, so I'd like to get a definitive True/False or Yes/No, not just printing nothing if it's not set.

I know that in a script, I can use "-z", but I'm not sure if/how I can do it directly from the command line.

I tried this: $ echo -z "${MY_URDSFDFS}"

But it just prints: -z

I want to know if a particular environment variable is set or not, from the command line. I need to distinguish between it being set to a blank string (or just whitespace) and not set at all, so I'd like to get a definitive True/False or Yes/No, not just printing nothing if it's not set.

I know that in a script, I can use -z, but I'm not sure if/how I can do it directly from the command line.

I tried this:

$ echo -z "${MY_URDSFDFS}"

But it just prints:

-z
Source Link
JoeMjr2
  • 161
  • 1
  • 1
  • 3

Check if environment variable is set from the command line

I want to know if a particular environment variable is set or not, from the command line. I need to distinguish between it being set to a blank string (or just whitespace) and not set at all, so I'd like to get a definitive True/False or Yes/No, not just printing nothing if it's not set.

I know that in a script, I can use "-z", but I'm not sure if/how I can do it directly from the command line.

I tried this: $ echo -z "${MY_URDSFDFS}"

But it just prints: -z