The Environment component is used to set and get the values of environment variables. By default every NSN script has an instance of this component as a global object named ENV that can access and change the NSN shell environment.
Clears the values of all the Environment variables.
object.Clear()
None.
Boolean. TRUE indicates that the environment variables are cleared.
This example clears all the environment variables of the shell.
’Displays all the environment variables.
’After executing this sample, exit and invoke the shell again.
name = Env.First
While name <> ""
value = Env.Get(name)
Print name & " " & value
name = Env.Next
Wend
’Clears all the environment variables and verify
Print "Clearing all the environment variables..."
env.Clear
name = Env.First
While name <> ""
value = Env.Get(name)
Print name & " " & value
name = Env.Next
Wend
Returns the first environment variable of the shell.
object.First()
None.
Name and Value, in the form name=value.
This example displays all the environment variables including the first one.
’Display all the environment variables
print "Environment Variables: "
name = Env.First
print "The first variable is name & " " & value
While name <> ""
value = Env.Get(name)
print name & " " & value
name = Env.Next
Wend
Returns the next environment variable; if no more variables are present, it returns NULL.
object.Next()
None.
Name and Value, in the form name=value.
This example displays all the environment variables.
’Display all the environment variables
print "Environment Variables: "
name = Env.First
While name <> ""
value = Env.Get(name)
print name & " " & value
name = Env.Next
Wend
Gets the value of a specified environment variable. It returns NULL if no variable is found.
object.Get(
Key As String)
String. Value of the specified variable.
This example creates the ROOT_DIR environment variable and gets it.
’Create a new variable ROOT_DIR
env.set ("ROOT_DIR", "Sys:NSN")
’Print the value
value=env.get ("ROOT_DIR")
print "Value of ROOT_DIR: " &value
Changes and sets the environment variable according to the specified value. If value is not specified then it clears the environment variable.
object.Set(
Key As String,
[Value As String])
Boolean. TRUE indicates that the environment variables are set.
This example creates a variable called ROOT_DIR and assigns a value Sys:NSN. It also shows how to clear the variable.
’Create a new variable ROOT_DIR
env.set ("ROOT_DIR", "Sys:NSN")
’Print the value
value=env.get ("ROOT_DIR")
print "Value of ROOT_DIR: " &value
’Clear the value
env.set ("ROOT_DIR")
’Print the value
value=env.get ("ROOT_DIR")
if (value = "") Then
print "Environment variable ROOT_DIR is cleared"
End if