官术网_书友最值得收藏!

The local variable and its scope

In the current shell, we can create and store user-defined variables. These may contain characters, digits, and _. A variable should not start with a digit. Normally, for environment variables, uppercase characters are used.

If we create a new variable, it will not be available in the subshells. The newly created variable will be available only in the current shell. If we run a Shell script, then the local variables will not be available in the commands called by the Shell script. Shell has one special variable, $$. This variable contains the process ID of the current shell.

Let's try a few commands:

This is the process ID of the current shell:

$ echo $$1234

We declare the variable name and initialize it:

$ name="Ganesh Naik"$ echo $nameGanesh Naik

This command will create a new subshell:

$ bash

This is the process ID of the newly created subshell:

$ echo $$1678

From the following, nothing will be displayed, as the local variables from the parent shell are not inherited in the newly created child shell or subshell:

$ echo $name

We will exit the subshell and return to the original shell Terminal:

$ exit

This is the process ID of the current shell or parent shell:

$ echo $$1234

This displays the presence of the variable in the original shell or parent shell:

$ echo $nameGanesh Naik

Variables created in the current shell will not be available in a subshell or child shell. If we need to use a variable in a child shell as well, then we need to export it using the export command.

主站蜘蛛池模板: 民和| 宜兴市| 衢州市| 辉南县| 大厂| 烟台市| 股票| 乌拉特前旗| 安新县| 巩义市| 广宁县| 五寨县| 威远县| 天峻县| 望都县| 开原市| 田林县| 易门县| 昌邑市| 墨竹工卡县| 道孚县| 灵武市| 壤塘县| 大城县| 法库县| 左权县| 乐亭县| 禹城市| 孙吴县| 河间市| 尼勒克县| 晋江市| 淮南市| 郁南县| 会昌县| 故城县| 山丹县| 方城县| 鄄城县| 鄂伦春自治旗| 讷河市|