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

Only in China! Alicloud container service enters the Forrester leader quadrant

基础:2.图像的本质

Guidelines and principles of did

Li Kou 1358 -- number of substrings containing all three characters (double pointer)

Share 7 books I read in the first half of 2022

如何一站式高效管理固定资产?
![Matlab [function derivation]](/img/ba/9fb9da8a458d0c74b29b21a17328fc.png)
Matlab [function derivation]

Advanced level of C language pointer (Part 1)

截图小妙招

TypeError: __ init__ () got an unexpected keyword argument ‘autocompletion‘
随机推荐
Shell脚本-字符串
Full mark standard for sports items in the high school entrance examination (Shenzhen, Anhui and Hubei)
R语言入门
Performance improvement 2-3 times! The second generation Kunlun core server of Baidu AI Cloud was launched
Shell脚本-select in循环
Embedded Engineer Interview Question 3 Hardware
V79.01 Hongmeng kernel source code analysis (user mode locking) | how to use the fast lock futex (Part 1) | hundreds of blogs analyze the openharmony source code
Computer tips
基础:3.opencv快速入门图像和视频
内存大小端
MySQL8.0学习记录17 -Create Table
Glitch free clock switching technology
Configuration and startup of Chang'an chain synchronization node
Introduction to 18mnmo4-5 steel plate executive standard and delivery status of 18mnmo4-5 steel plate, European standard steel plate 18mnmo4-5 fixed rolling
中考体育项目满分标准(深圳、安徽、湖北)
factory type_ Id:: create process resolution
It is designed with high bandwidth, which is almost processed into an open circuit?
Introduction to R language
What is the material of 16mo3 steel plate? What is the difference between 16mo3 and Q345R?
[untitled]