当前位置:网站首页>Basic series of SHEL script (I) variables
Basic series of SHEL script (I) variables
2022-07-05 07:19:00 【jiankang66】
One 、 background
Although I am a java The programmer , Do the back end , But recently, I often need to read scripts written by others to run projects , So as a back-end programmer , We also need to know shell grammar , Can read some basic shell Script .
Two 、 Variable correlation
1、 Variable assignment
(1) Assignment of common variables
a="hello world"
(2) Assign values to variables through commands , Two ways .
a=$(pwd)
b=`uname`
2、 Cancel variables
unset A
3、 Get the length of the variable
${#b}
4、 Deletion of variable content
(1) Delete Syntax
% | Means to remove the first matching from right to left |
%% | Remove all matching from right to left |
# | Means to remove the first matching from left to right |
## | Means to remove all matching from left to right |
eg:
# return text
a=a.txt
echo ${a##*.}
4、 Replacement of variable contents
(2) Substitution grammar
${ Variable name / The old value / The new value }
eg:
# return b.txt
a=a.txt
echo ${a/a/b}
5、 Print variables
(1) Mode one
echo $a
(2) Mode two
echo ${a}
6、 Query environment variables
(1) View the current environment variables
env
(2) Filter environment variables
env | grep Name
(3) Support filtering common variables or environment variables
set | grep Name
7、 Define an environment variable
(1) Mode one
declare -x BBB=jiankang
(2) Mode two
export DDD=jiankang
8、 Global variable profile
(1) Required after change source Let it take effect
Configure environment variables globally | /etc/profile |
Current user's environment variables | home/.bash_profile |
Current user's bash Information | /home/.bashrc |
Global effective for all users bash Information | /etc/bashrc |
9、 System variables
$? | Whether the last command is executed normally 0 Is normal ( really ) Not 0 Indicates an execution exception |
$0 | Name of the currently executing program or script |
$# | The number of parameters passed after the script |
$* | All the parameters behind the script , Comma separated |
[email protected] | All the parameters behind the script |
$1 | The first parameter following the script |
$9 | The ninth parameter following the script |
${10} | The tenth parameter following the script |
$$ | The process number of the current process |
$! | The last process number running in the background ( Current terminal ) |
!$ | Call the parameters in the last command history |
3、 ... and 、 summary
The above is about shell Everything about syntax variables , Hopefully that helped , You can refer to it , If you think it's good , Welcome to wechat search java Basic notes , Relevant knowledge will be continuously updated later , Make progress together .
边栏推荐
- PHY drive commissioning - phy controller drive (II)
- 【Node】nvm 版本管理工具
- [vscode] recommended plug-ins
- Hdu1231 maximum continuous subsequence (divide and conquer or dynamic gauge or double pointer)
- Literacy Ethernet MII interface types Daquan MII, RMII, smii, gmii, rgmii, sgmii, XGMII, XAUI, rxaui
- Use of Pai platform
- postmessage通信
- R language learning notes 1
- Solve tensorfow GPU modulenotfounderror: no module named 'tensorflow_ core. estimator‘
- Application of MATLAB in Linear Algebra (4): similar matrix and quadratic form
猜你喜欢
Do you choose pandas or SQL for the top 1 of data analysis in your mind?
Powermanagerservice (I) - initialization
Mathematical analysis_ Notes_ Chapter 8: multiple integral
[software testing] 02 -- software defect management
Logical structure and physical structure
Special training of C language array
1290_ Implementation analysis of prvtaskistasksuspended() interface in FreeRTOS
Brief description of inux camera (Mipi interface)
第 2 章:小试牛刀,实现一个简单的Bean容器
Anaconda navigator click open no response, can not start error prompt attributeerror: 'STR' object has no attribute 'get‘
随机推荐
Rough notes of C language (2) -- constants
Today, share the wonderful and beautiful theme of idea + website address
Delayqueue usage and scenarios of delay queue
Tshydro tool
纯碱是做什么的?
GPIO port bit based on Cortex-M3 and M4 with operation macro definition (can be used for bus input and output, STM32, aducm4050, etc.)
[node] differences among NPM, yarn and pnpm
Simple operation with independent keys (hey, a little fancy) (keil5)
Logical structure and physical structure
Steps and FAQs of connecting windows Navicat to Alibaba cloud server MySQL
CADD课程学习(6)-- 获得已有的虚拟化合物库(Drugbank、ZINC)
Ggplot2 drawing learning notes in R
Mathematical analysis_ Notes_ Chapter 8: multiple integral
剑指 Offer 56 数组中数字出现的次数(异或)
PostMessage communication
SD_ CMD_ SEND_ SHIFT_ REGISTER
Concurrent programming - how to interrupt / stop a running thread?
Intelligent target detection 59 -- detailed explanation of pytoch focal loss and its implementation in yolov4
Now there are HTML files and MVC made with vs (connected to the database). How can they be connected?
Lexin interview process