当前位置:网站首页>Shell script - definition, assignment and deletion of variables
Shell script - definition, assignment and deletion of variables
2022-07-01 08:47:00 【Little snail's way】
Tradition : What is? Shell
- Shell It's an application , It connects the user and Linux kernel , Let users be more efficient 、 Security 、 Low cost local use Linux kernel , This is it. Shell The essence of .
- Shell It's also a programming language , Its compiler ( Interpreter ) yes Shell This procedure .
- Shell Is a scripting language , We do not need to compile the source code , Run the source code directly .
Shell Script format
With #!/bin/bash start
#!/bin/bash
···
Shell Variable :Shell Definition of variables 、 Assignment and deletion
Recommended values value Surround with quotation marks
variable='value'
variable="value"
The difference between single quotation mark and double quotation mark
- Single quote ’ ' When enclosing the value of a variable , Output what is in single quotation mark
- Double quotation marks " " When enclosing the value of a variable , The variables and commands in the output will be parsed first , Instead of outputting the variable names and commands in double quotes as they are
#!/bin/bash
author='jack'
name=' The writer's name is ${author}'
name2=" The writer's name is ${author}"
echo ${name}
echo ${name2}
Run the script output :
The writer's name is ${author}
The writer's name is jack
Assign the execution result of the command to the variable
It supports assigning the execution result of a command to a variable , Surround the command variable=$(command)
#!/bin/bash
out=$(sh test.sh)
echo ${out}
Output
The writer's name is ${author} The writer's name is jack
A read-only variable
Use readonly Commands can define variables as read-only variables , The value of a read-only variable cannot be changed .
The following example attempts to change a read-only variable , The result is wrong :
#!/bin/bash
name='jack'
readonly name
name='rose'
echo ${name}
Output
test3.sh: line 5: name: readonly variable
Delete variables
Use unset Command to delete variables . grammar unset variable_name
Variable cannot be used again after being deleted ;unset Command cannot delete read-only variables .
#!/bin/bash
name='jack'
unset name
echo ${name}
Output
边栏推荐
- Memory size end
- ARM v7的体系结构A、R、M区别,分别应用在什么领域?
- 1. Connection between Jetson and camera
- 固定资产管理系统让企业动态掌握资产情况
- It is designed with high bandwidth, which is almost processed into an open circuit?
- What is the material of 16MnDR, the minimum service temperature of 16MnDR, and the chemical composition of 16MnDR
- Advanced API
- 个人装修笔记
- 中小企业固定资产管理办法哪种好?
- 目标检测的yolov3、4、5、6总结
猜你喜欢
随机推荐
Promise异步编程
Matlab [function derivation]
"Analysis of 43 cases of MATLAB neural network": Chapter 30 design of combined classifier based on random forest idea - breast cancer diagnosis
C language student information management system
MATLAB【函数和图像】
如何一站式高效管理固定资产?
FreeRTOS learning easy notes
Principle and application of single chip microcomputer - off chip development
个人装修笔记
任务、线程、进程 区别
《微机原理》——微处理器内部及外部结构
Brief introduction to AES
Public network cluster intercom +gps visual tracking | help the logistics industry with intelligent management and scheduling
Advanced API
Only in China! Alicloud container service enters the Forrester leader quadrant
《单片机原理与应用》——并行IO口原理
截图小妙招
Insert mathematical formula in MD document and mathematical formula in typora
ARM v7的体系结构A、R、M区别,分别应用在什么领域?
5mo3 UHI HII HII 17mn4 19Mn6 executive standard









