Linux Bash Guide -- echo : Creating variables and Exporting variables

Опубликовано: 06 Март 2017
на канале: WPJ852
231
0

1. Creating variables
Variables are case sensitive and capitalized by default. Giving local variables a lowercase name is a convention which is sometimes applied. However, you are free to use the names you want or to mix cases. Variables can also contain digits, but a name starting with a digit is not allowed.

To set a variable in the shell, use

VARNAME="value"

Putting spaces around the equal sign will cause errors. It is a good habit to quote content strings when assigning values to variables: this will reduce the chance that you make errors.

2. Exporting variables
A variable created like the ones in the example above is only available to the current shell. It is a local variable: child processes of the current shell will not be aware of this variable. In order to pass variables to a subshell, we need to export them using the export built-in command. Variables that are exported are referred to as environment variables. Setting and exporting is usually done in one step:

export VARNAME="value"

A subshell can change variables it inherited from the parent, but the changes made by the child don't affect the parent.


Смотрите видео Linux Bash Guide -- echo : Creating variables and Exporting variables онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь WPJ852 06 Март 2017, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 231 раз и оно понравилось 0 людям.