Перейти к содержанию

Variables


Shell variables.

Namespace of that variables - only current bash session. To spread it to another sessions - describe them on ~/.bashrc

describe variale var_name
var_name=var_value
$var_name - refer to var_name. For example, we can display it with echo.

Variable name can contains number, but can't begin with them. Also can't contains special characters, except sign _.

If variable name contains spaces - use double quotes to describe them.

Variable can contains expression. In this case, describe var like:

cur_version=$(uname -r)
# or next deprecated method
cur_version=`uname -r
another one example:
head -2 $(grep -rl bash /etc/ 2> /dev/null)

Environment variables.

Use for exhange data between programs. Store on /etc/profile, /etc/environment, ~/bash_profile or ~/.bashrc

env - show all those varibles.

export - add variable to env