I'm writing a Korn Shell.
I want to assign default values to environment variables only if they
are
not already set. A null string value is valid.
ex.
Before invoking script.
export str1="hello"
export str2=
unset str3
Now inside my script I want the following logic, (pseudo code)
if ( $str1 doesn't exist )
export str1="str1 set to default"
fi
if ( $str2 doesn't exist )
export str3="str2 set to default"
fi
if ( $str3 doesn't exist )
export str3="str3 set to default"
fi
print "str1= $str1"
print "str2= $str2"
print "str3= $str3"
I should see the following on the screen:
str1= hello
str2=
str3= str3 set to default
My problem is that I don't know how to detect the difference between an
unset variable and a variable whose value is null.
( i.e. str2 and str3 ).
Does anybody know how?
Thanks in advance.
Jeff