environment variables
List, read, set and remove environment variables, for a command or for the session.
Steps
-
printenv | sortevery variable
-
echo "$HOME"one of them
-
export NAME=valueset one for this shell and what it starts
-
NAME=value commandset one for one command only
-
unset NAMEremove one
-
set -a; source .env; set +aload a file of NAME=value lines into the shell
Notes
- To keep a variable, put the export line in ~/.bashrc (or ~/.zshrc).
Commands used
printenvexportenv
Each has a page in lore: lore printenv opens it.
Related recipes
- add a folder to the pathLet the shell find programs in a folder, for good, and reload the settings without logging out.
- add to the end of a fileAdd lines to a file without replacing it, also to a file only root can write.
- argument list too long"Argument list too long" from rm, cp or mv: too many files for one command line. Hand them over in batches.
- ask for input in a scriptAsk yes or no, read a password without showing it, or wait for an answer with a time limit.