当前位置:网站首页>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
边栏推荐
- Introduction to 18mnmo4-5 steel plate executive standard and delivery status of 18mnmo4-5 steel plate, European standard steel plate 18mnmo4-5 fixed rolling
- AES简单介绍
- C语言学生信息管理系统
- 《微机原理》——微处理器内部及外部结构
- What is the material of 16MnDR, the minimum service temperature of 16MnDR, and the chemical composition of 16MnDR
- Programming with C language: calculate with formula: e ≈ 1+1/1+ 1/2! …+ 1/n!, Accuracy is 10-6
- 《单片机原理及应用》—定时器、串行通信和中断系统
- Li Kou 1358 -- number of substrings containing all three characters (double pointer)
- Audio-AudioRecord create(一)
- 19Mn6 German standard pressure vessel steel plate 19Mn6 Wugang fixed binding 19Mn6 chemical composition
猜你喜欢

FreeRTOS learning easy notes

Computer tips
![Matlab [function derivation]](/img/ba/9fb9da8a458d0c74b29b21a17328fc.png)
Matlab [function derivation]

SPL Introduction (I)

Nacos - gestion de la configuration

3. Detailed explanation of Modbus communication protocol

C语言指针的进阶(下)

15Mo3 German standard steel plate 15Mo3 chemical composition 15Mo3 mechanical property analysis of Wuyang Steel Works

电视机尺寸与观看距离

Nacos - 服务发现
随机推荐
大型工厂设备管理痛点和解决方案
Shell脚本-数组定义以及获取数组元素
Shell脚本-变量的定义、赋值和删除
【无标题】
NFT监管要点和海外政策
C language student information management system
Advanced level of C language pointer (Part 1)
Promise异步编程
集团公司固定资产管理的痛点和解决方案
为什么LTD独立站就是Web3.0网站!
What is 1cr0.5mo (H) material? 1cr0.5mo (H) tensile yield strength
电视机尺寸与观看距离
What is the material of 16mo3 steel plate? What is the difference between 16mo3 and Q345R?
Bimianhongfu queren()
你了解数据是如何存储的吗?(C整型和浮点型两类)
Shell脚本-字符串
DataBinding源码分析
It technology ebook collection
Computer tips
SPL installation and basic use (II)