当前位置:网站首页>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
边栏推荐
猜你喜欢

Vscode customize the color of each area

5mo3 UHI HII HII 17mn4 19Mn6 executive standard
![Matlab [function derivation]](/img/ba/9fb9da8a458d0c74b29b21a17328fc.png)
Matlab [function derivation]

Matlab tips (16) consistency verification of matrix eigenvector eigenvalue solution -- analytic hierarchy process

Nacos - gestion de la configuration

What is the material of 16MnDR, the minimum service temperature of 16MnDR, and the chemical composition of 16MnDR

《单片机原理与应用》——并行IO口原理

TV size and viewing distance

Installing Oracle EE

基础:2.图像的本质
随机推荐
Model and view of QT
明明设计的是高带宽,差点加工成开路?
JCL 和 SLF4J
Pipeline detection of UAV Based on gazebo
Nacos - gestion de la configuration
19Mn6 German standard pressure vessel steel plate 19Mn6 Wugang fixed binding 19Mn6 chemical composition
《微机原理》——微处理器内部及外部结构
SPL Introduction (I)
jeecg 重启报40001
Principle and application of single chip microcomputer - off chip development
截图小妙招
Shell脚本-变量的定义、赋值和删除
Matlab [function derivation]
软件工程师面试刷题网站、经验方法
Foundation: 2 The essence of image
Bimianhongfu queren()
长安链同步节点配置与启动
《单片机原理与应用》——并行IO口原理
Introduction to 18mnmo4-5 steel plate executive standard and delivery status of 18mnmo4-5 steel plate, European standard steel plate 18mnmo4-5 fixed rolling
Audio audiorecord create (I)