Env class

Sets gets an environment variable for the current process.

Passing a null value will remove the key from the set of environment variables.

Any child process spawned will inherit these changes. e.g.

  /// Set the environment variable 'XXX' to 'A Value'
  env['XXX'] = 'A Value';

  // the echo command will display the value off XXX.
  '''echo $XXX'''.run;

  /// Get the current value of an environment variable
  var xxx = env['XXX'];

NOTE: this does NOT affect the parent processes environment.

Implementation class for the functions env[] and env[]=.

Constructors

Env()
Implementation class for the functions env[] and env[]=. Returns a singleton unless we are running in a Scope and a scopeKey for Env has been placed into the scope.
factory
Env.forScope(Map<String, String> map)
Use this ctor for injecting an altered Environment into a Scope. The main use for this ctor is for unit testing.
factory

Properties

delimiterForPATH String
returns the delimiter used by the PATH enviorment variable.
no setter
entries Iterable<MapEntry<String, String>>
Returns the complete set of Environment variable entries.
no setter
hashCode int
The hash code for this object.
no setterinherited
HOME String
Gets the path to the user's home directory using the enviornment var appropriate for the user's OS.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

addAll(Map<String, String> other) → void
Adds all of the entries in the other map as environment variables. Case translation will occur if the platform is case sensitive.
addToPATHIfAbsent(String newPath) → void
Adds newPath to the PATH environment variable if it is not already present.
appendToPATH(String newPath) → void
Appends newPath to the list of paths in the PATH environment variable.
exists(String key) bool
Returns true if an environment variable with the name key exists.
fromJson(String json) → void
Takes a json string created by toJson clears the current set of environment variables and replaces them with the environment variables encoded in the json string.
isOnPATH(String checkPath) bool
returns true if the given checkPath is in the list of paths defined in the environment variable PATH.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
prependToPATH(String newPath) → void
Prepends newPath to the list of paths in the PATH environment variable provided the path isn't already on the PATH.
removeFromPATH(String oldPath) → void
Removes the given oldPath from the PATH environment variable.
toJson() String
Encodes all environment variables to a json string. This method is intended to be used in conjuction with fromJson.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited
operator [](String name) String?
Returns the value of an environment variable.
operator []=(String name, String? value) → void
Sets the value of an environment variable

Static Properties

scopeKey ↔ ScopeKey<Env>
getter/setter pair