- Learning Linux Shell Scripting
- Ganesh Naik
- 272字
- 2021-06-25 22:02:55
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.
- 構(gòu)建高質(zhì)量的C#代碼
- 中文版Photoshop CS5數(shù)碼照片處理完全自學(xué)一本通
- 傳感器技術(shù)實(shí)驗(yàn)教程
- 數(shù)控銑削(加工中心)編程與加工
- Apache Hive Essentials
- 機(jī)器學(xué)習(xí)與大數(shù)據(jù)技術(shù)
- MicroPython Projects
- ROS機(jī)器人編程與SLAM算法解析指南
- 城市道路交通主動(dòng)控制技術(shù)
- JavaScript典型應(yīng)用與最佳實(shí)踐
- FPGA/CPLD應(yīng)用技術(shù)(Verilog語(yǔ)言版)
- 實(shí)用網(wǎng)絡(luò)流量分析技術(shù)
- Citrix? XenDesktop? 7 Cookbook
- 格蠹匯編
- MATLAB-Simulink系統(tǒng)仿真超級(jí)學(xué)習(xí)手冊(cè)