Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

check if environment variable is set

Status
Not open for further replies.

gotchausa

Programmer
Jan 24, 2002
64
CA
How I do the following in Solaris:
1. Check to see of environ. variable $TAPE is set.
2. If it is not, then set it to /dev/rmt/0n
3. If it is set, then dont do anything.
 
#!/bin/ksh

if [ ! -n "${TAPE}" ]; then
TAPE='/dev/rmt/0n'
fi;


OR alternatively [in ksh]:

${TAPE:=/dev/rmt/0n}
 
I have tried these methods within my script but when I exit the script and do:

echo $TAPE

I dont get /dev/rmt/0n as expected. I get whatever it was before (e.e emty output if it was not set).
 
mpv:

When you execute a script it spawns a new shell, and shell variables defined in the child process are not automatically passed back to the parent. If your script is called myscript.ss and runs in ksh and sh, you need to use the dot operator:

. myscript.ss # space after the "."

This was covered extensively in this forum under thread:

thread822-255445

Regards,

Ed
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top