System variables, often called the environmental variables are defined and stored in the parent environment (a shell from which your scripts run). Their names are usually created with large letters and may be tested command set. Defines the user environment, accessible to all child processes
Environment variables and their scope:
- Global - visible in every undersell;
- Local - only visible to the shell in which it was set
To further illustrate the difference between them, let's do a little experiment: go to any terminal (seen undershell) and type:
x ="string"
echo $ x
xterm
x ="string" is defined a variable x, which has the value "string"
echo $ x displays the value of the variable x
xterm call undershell
echo $ x
xterm
x ="string" is defined a variable x, which has the value "string"
echo $ x displays the value of the variable x
xterm call undershell
type this again:
echo $ x does not show anything because local variables are not visible in undershells
Initialize global variables:
export x ="string"
Now the variable x will be visible in undershells, as seen above, this command is used to export, it gives the specified variable attribute global variables. If you write the same export, export-p option will get a list of currently exported variables. In this list before the name of each variable's entry:
declare -x
This internal BASH command, used to define variables and give them attributes,-x is an attribute that is exports is the same as the export command.
Note! Declare command occurs only in BASH, it's not in the other shells, while the export is in ksh, ash and others that use the startup file /etc/profile.
It is recommended to use the export command.
export -n variable
Will remove the export attribute for a variable
Some examples of environment variables:
$HOME path to your home directory
$USER your login
$HOSTNAME your hostname
$OSTYPE type of operating system
$UID Unique User ID - a unique user number
$TERM The terminal type for what you use
And much, much more all available environment variables can be displayed via the command:
printenv | less
In some systems there printenv command, you can use env.
System variables refer to the same as normal.
By defining the variables as a system, be sure to share command exports variables coatings child (undershells):
bash $ SCRIPT_PATH = / usr / bin / script.sh
bash $ export SCRIPT_PATH
bash $ export SCRIPT_PATH
Note:
Note the lack of character $ in using the export command!
Modern coating system lets you do this in one line:
bash$ export SCRIPT_PATH=/usr/bin/script.sh