Bash environment
more infos at http://doc.ubuntu-fr.org/variables_d_environnement
Contents
Assign values to environment variables
To assign a value to an existing environment variable, we use an assignment expression. For example, to assign the "en_US.UTF-8" value to the variable "LANG", we use the following command:
LANG=fr_FR.UTF-8
If we use an assignment expression to a variable that does not exist, the shell will create a "shell variable", which is similar to an environment variable, but that will not affect the behavior of other applications.
A shell variable can be exported to become an environment variable with the export command. To create the environment variable "EDITOR" and assign the value "nano", several methods can be used. Here's one we propose:
EDITOR=nano export EDITOR
The bash shell (the one that comes by default with Ubuntu) provides a shortcut for creating environment variables. The previous example can be condensed into a single command line:
export EDITOR=nano
Examine the values of environment variables
The printenv command displays the names and values of all environment variables set:
printenv
To examine the value of a particular variable, simply specify its name after the printenv command:
printenv TERM
The variable's value can be retrieved using the "$" sign in front of his name, as in the following example:
echo $TERM
There is a command to make temporary changes in the short term, on the environment. This can also be used to display the current environment variables. This is the env command:
env
The dollar sign can be used to retrieve the value of environment variables in command lines. For example, the following command can be used to list the desktop files (Desktop folder) of the current user:
ls $HOME/Desktop
Clear environment variables In most cases, assign an empty value for an environment variable enough to cancel its effect, as in the example below. However, some variables such as "POSIXLY_CORRECT" influence the programs of their very existence, even if their value is empty.
export LC_ALL=
The unset command can be used to completely remove an environment variable:
unset LC_ALL
It is also possible to use the export command with the -n argument. This will result in losing the variable sound environment variable status, it becomes a shell variable while retaining its value.
export -n LC_ALL
main variables of environment
User Environment
Variable | Example value | Role |
---|---|---|
USERNAME | user_name | The user name currently connected. This variable is defined by the système.Vous certainly should not change its value manually. |
LOGNAME | user_name | Similar to USER, some programs use it in preference to USER |
HOME | /home/utilisateur | Location user's home directory currently connected. |
PWD | /home/utilisateur/Desktop | The current working directory of the shell. |
SHELL | /bin/bash | The preferred shell as the user that is defined in the "/ etc / passwd" |
POSIXLY_CORRECT | s.o. | The very existence of this environment variable, regardless of its value, forcing some utilities to behave in a manner more consistent with the POSIX standard. This can cause dysfunction of various GNU tools that make life easier, but it may be just what is sought to properly operate old UNIX scripts. |
HOSTALIASES | /etc/host.aliases | The file name containing guest alias names for use with a variety of network software. |
TZDIR | /usr/share/zoneinfo | The path of the folder containing the information on time zones files (TimeZoneDIRectory) .It is usually no need to manually set as systems seek such files in / usr / share / zoneinfo, by default. |
TZ | IST-2:Japan | This variable was used by the ancient Unix systems to specify the time zone of the system. However, Ubuntu and most newer systems use for that / etc / localtime. It can be used to néamoins a particular user session displays the time in a different time zone from that of the system. The value of this variable can be either the name and offset from one time zone (first example) or the name of a zone file located in / usr / share / zoneinfo (second example). |
TERM | xterm | The name of the terminal on information files located in / lib / terminfo, this file tells the program in console mode how to perform tasks such as color display. It may be useful to play with this variable if you try to use an unusual terminal emulation program, or if you try to connect a terminal emulator hardware via serial port and you do not get the desired results. |
TERMCAP | This variable can be used instead of "TERM" to specify the information on the device manually, instead of using a file. | |
COLUMNS | 80 | The number of columns on the console window. Try adjusting this variable if lines do not wrap sccm to juste in the console. |
LINES | 25 | The number of lines in the console window. Try adjusting this variable if you get strange results when you scroll the text. |
http_proxy | http://user:passwd@proxy:port/ | The variable to use a proxy, also works with HTTP_PROXY, ftp_proxy and FTP_PROXY |
Regional Environment
Variable | Role |
---|---|
$LANG | The basic language setting used by system applications, as long as it is not contradicted by another variable |
$LC_CTYPE | The character set used to enter and display text |
$LC_NUMERIC | Formatting non-monetary numeric values |
$LC_TIME | Format for date and time |
$LC_COLLATE | How to sort various information such sets alphabetical order so that the items can be sorted alphabetically using the sort command |
$LC_MONETARY | Format monetary numeric values |
$LC_MESSAGES | Language used to display messages to the user |
$LC_PAPER | Definitions of standard paper sizes |
$LC_NAME | Format names |
$LC_ADDRESS | Addresses Format |
$LC_TELEPHONE | Structure of telephone numbers |
$LC_MEASUREMENT | Measurement units to use |
$LC_IDENTIFICATION | |
$LC_ALL | This variable has a powerful role to crush the other locales. When a value is assigned, applications use this value regardless of the values of other variables |