Hi, How to identify if a ksh environment variable has been created by export command in the script.
i.e., export abc=xyz
What is the way to identify if abc exist.
Thanks, Mike
Actually, the Korn shell has a whole set of variable expansion formats to deal with this issue. If you don't know if variable ABC is set, you can do the following.
If you just want to tell if it's set or not, the command...
[tt]
print ${ABC:+"ABC has been set"}
[/tt]
...will do that. If you want to check the opposite, the command...
[tt]
print ${ABC:-"ABC has not been set"}
[/tt]
...will print whatever ABC is set to if it is set and not null, or, whatever's after the "[tt]:-[/tt]" if not. This can be either a string or another variable.
In either of these, you can put either a string or a variable in the last half.
If you do this...
[tt]
print ${ABC:?}
[/tt]
...it will print the value ABC is set to, if it is set, or "[tt]ksh: ABC: parameter null or not set[/tt]" if it's not.
If you do this...
[tt]
print ${ABC:?"Missing variable, terminating!"}
[/tt]
...it will print the value ABC is set to, if it is set, or will print the string and Exit the script if it's not.
If you do this...
[tt]
print ${ABC:="Something"}
[/tt]
...it will print the value ABC is set to, if it is set, or will assign the value that's after the "[tt]:=[/tt]" to ABC, then print it. This will either use a variable if set, or set it if it's not set.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.