Managing environment variables
This page details all the user-facing commands in the main mode which deal with reading and writing environment variables. The changes to the variables are applied to the environment of the shell the command was executed in.
All commands are offered through shortcuts to ease access to the core functions.
Note
These commands are only available if Envprobe has been hooked in the current shell.
Reading (get
, ?
)
- get(VARIABLE, info=False)
Read and print the value of the environment variable
VARIABLE
to the standard output in the formatVARIABLE=value
.- Parameters
VARIABLE – The name of the environment variable to query.
info (
True
if-i
orinfo
is given) – Whether to print additional information.
- Possible invocations
ep get [-i|--info] VARIABLE
ep ?VARIABLE
ep VARIABLE
1
- Examples
$ ep PATH PATH=/usr/local/bin:/usr/bin:/sbin:/bin
$ ep get -i PATH PATH=/usr/local/bin:/usr/bin:/sbin:/bin PATH= /usr/local/bin /usr/bin /sbin /bin Type: 'path'
- Priting additional information:
If
-i
/--info
is given, additional information about the variable will be printed after the initial print of the value. This additional information includes:The individual elements of the variable in order if it is an array variable (
Array
), after the variable name repeated, one per line.The type class of the variable within Envprobe.
Additional stored information such as a description of the variable, based on the stored configuration or the downloaded community knowledge-base.
- 1
The shorthand format
ep VARIABLE
forep get VARIABLE
is available only if the given variable name ("VARIABLE"
) is not “shadowed” by a subcommand name that is valid at the time the command is executed. E.g. ifget
is an environment variable defined in the shell, sayingep get
will not be resolved as if the user saidep get get
, but instead, it will simply callep get
without a variable name, resulting in an error. As most environment variables are named in SCREAMING_SNAKE_CASE, this should not pose an issue except in the rarest of situations.
Writing (set
, !
, =
)
- set(VARIABLE, VALUE)
Set the value of
VARIABLE
to the specifiedVALUE
.- Parameters
VARIABLE – The name of the environment variable to set.
VALUE – The new value to set to.
- Possible invocations
ep set VARIABLE VALUE
ep !VARIABLE VALUE
ep VARIABLE=VALUE
- Examples
$ echo $SOME_VARIABLE # No result, the variable is not set. $ ep set SOME_VARIABLE MyValue $ echo $SOME_VARIABLE MyValue
$ which ls /bin/ls $ ep PATH PATH=/usr/local/bin:/usr/bin:/sbin:/bin $ ep PATH="/tmp" $ which ls # No result.
Undefining (undefine
, ^
)
- undefine(VARIABLE)
Undefine the
VARIABLE
.In some cases, there can be subtle differences between a variable that is defined (but usually empty string), and variables that are not defined at all. However, in many cases, the two are equivalent.
- Parameters
VARIABLE – The name of the environment variable to undefine.
- Possible invocations
ep undefine VARIABLE
ep ^VARIABLE
- Examples
$ echo $USER root $ ep undefine USER $ echo $SOME_VARIABLE # No result, the variable is not set.
$ echo $HOME/bin /home/user/bin $ ep ^HOME $ echo $HOME/bin /bin
Adding to arrays (add
, +
)
Traditionally, extending a variable such as PATH
with your current working directory required executing a lengthy sequence: export PATH="$(pwd):${PATH}"
.
- add(VARIABLE, VALUE..., position=0)
Add the given
VALUE
(or values, can be multiple) to theVARIABLE
array. The values will be located starting at the givenposition
index, while all subsequent elements will be shifted to the right (to higher indices).- Parameters
VARIABLE – The name of the environment variable to add to.
VALUE – The value(s) to add.
position (int) – The position where the added value(s) will be put to. A positive position counts from the beginning of the array, while a negative position counts from the end.
0
is the first, and-1
is the last element’s position.
- Possible invocations
ep add [--position] VARIABLE VALUE
ep +VARIABLE VALUE
(forposition = 0
)ep VARIABLE+ VALUE
(forposition = -1
)
- Examples
$ ep PATH PATH=/usr/local/bin:/usr/bin:/sbin:/bin $ fancy fancy: command not found! $ ep add --position 0 PATH /opt/fancy/bin $ fancy Fancy tool works! $ ep PATH PATH=/opt/fancy/bin:/usr/local/bin:/usr/bin:/sbin:/bin
$ ep SOME_ARRAY SOME_ARRAY=Foo:Bar:Baz # ^0 ^1 ^2 # -3^ -2^ -1^ $ ep add --position 1 SOME_ARRAY BLAH $ ep SOME_ARRAY SOME_ARRAY=Foo:BLAH:Bar:Baz # ^0 ^1 ^2 ^3 # -4^ -3^ -2^ -1^ $ ep add --position -2 SOME_ARRAY FIZZ $ ep SOME_ARRAY SOME_ARRAY=Foo:BLAH:FIZZ:Bar:Baz
$ ep PATH PATH=/usr/local/bin:/usr/bin:/sbin:/bin $ ep PATH+ / $ ep PATH PATH=/usr/local/bin:/usr/bin:/sbin:/bin:/
Note
The
add
command only works with environment variables that areArray
. In case Envprobe did not correctly resolve the type of the variable, you can configure it yourself.
Removing from arrays (remove
, -
)
- remove(VARIABLE, VALUE...)
Remove all occurrences of
VALUE
(or values, can be multiple) from theVARIABLE
array.- Parameters
VARIABLE – The name of the environment variable to remove from.
VALUE – The value(s) to remove.
- Possible invocations
ep remove VARIABLE VALUE
ep -VARIABLE VALUE
- Examples
$ ep PATH PATH=/opt/fancy/bin:/usr/local/bin:/usr/bin:/sbin:/bin $ fancy Fancy tool works! $ ep remove PATH /opt/fancy/bin $ fancy fancy: command not found! $ ep PATH PATH=/usr/local/bin:/usr/bin:/sbin:/bin
$ ep PATH PATH=/bin:/bin:/bin:/usr/local/bin:/bin:/usr/bin:/sbin:/bin:/bin:/bin $ ep -PATH /bin $ ep PATH PATH=/usr/local/bin:/usr/bin:/sbin
Note
The
remove
command only works with environment variables that areArray
. In case Envprobe did not correctly resolve the type of the variable, you can configure it yourself.