Up: Environment   [Contents][Index]


3.3.4.1 env: legacy syntax.

Up to version 1.3 pies implemented the one-line variant of the env statement. The use of this legacy syntax is discouraged. It is supported for backward compatibility only and will be removed in future versions. This subsection describes the legacy syntax.

legacy syntax: env args

Set program environment.

Arguments are a whitespace-delimited list of specifiers. The following specifiers are understood:

- (a dash)

Clear the environment. This is understood only when used as a first word in args.

The modern syntax equivalent is:

env {
  clear;
}
-name

Unset the environment variable name. The modern syntax equivalent is

env {
  unset name;
}
-name=val

Unset the environment variable name only if its value is val. The modern syntax equivalent is:

env {
  unset "name=val";
}
name

Retain the environment variable name. The modern syntax equivalent is

env {
  keep name;
}
name=value

Define environment variable name to have given value. The modern syntax equivalent is:

env {
  keep "name=value";
}
name+=value

Retain variable name and append value to its existing value. If no such variable is present in the environment, it is created and value is assigned to it. However, if value begins with a punctuation character, this character is removed from it before the assignment. This is convenient for using this construct with environment variables like PATH, e.g.:

PATH+=:/sbin

In this example, if PATH exists, ‘:/sbin’ will be appended to it. Otherwise, it will be created and ‘/sbin’ will be assigned to it.

In modern syntax, use shell variable references, e.g.:

env {
  set "PATH=${PATH}${PATH:+:}/sbin";
}
name=+value

Retain variable name and prepend value to its existing value. If no such variable is present in the environment, it is created and value is assigned to it. However, if value ends with a punctuation character, this character is removed from it before assignment.

In modern syntax, use shell variable references, e.g. instead of doing

env PATH=+/sbin:

use

env {
  set "PATH=/sbin${PATH:+:}$PATH";
}

Up: Environment   [Contents][Index]