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
VARIABLEto the standard output in the formatVARIABLE=value.- Parameters
VARIABLE – The name of the environment variable to query.
info (
Trueif-iorinfois given) – Whether to print additional information.
- Possible invocations
ep get [-i|--info] VARIABLEep ?VARIABLEep VARIABLE1
- 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/--infois 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 VARIABLEforep get VARIABLEis 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. ifgetis an environment variable defined in the shell, sayingep getwill not be resolved as if the user saidep get get, but instead, it will simply callep getwithout 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
VARIABLEto the specifiedVALUE.- Parameters
VARIABLE – The name of the environment variable to set.
VALUE – The new value to set to.
- Possible invocations
ep set VARIABLE VALUEep !VARIABLE VALUEep 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 VARIABLEep ^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 theVARIABLEarray. The values will be located starting at the givenpositionindex, 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.
0is the first, and-1is the last element’s position.
- Possible invocations
ep add [--position] VARIABLE VALUEep +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
Using--positionto control where the values will be added to. Note the^1markers indicating what the individual variables’ positions are understood as.$ 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
addcommand 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 theVARIABLEarray.- Parameters
VARIABLE – The name of the environment variable to remove from.
VALUE – The value(s) to remove.
- Possible invocations
ep remove VARIABLE VALUEep -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
All occurrences are removed. The following array has/binin it 7 times.$ 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
removecommand only works with environment variables that areArray. In case Envprobe did not correctly resolve the type of the variable, you can configure it yourself.