当前位置:网站首页>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 .
边栏推荐
- [framework] multi learner
- [software testing] 04 -- software testing and software development
- [vscode] search using regular expressions
- Ros2 - ros2 vs. ros1 (II)
- ModuleNotFoundError: No module named ‘picamera‘
- What if the DataGrid cannot see the table after connecting to the database
- M2DGR 多源多场景 地面机器人SLAM数据集
- Import CV2 prompt importerror: libgl so. 1: Cannot open shared object file: no such file or directory
- [solved] there is something wrong with the image
- Altimeter data knowledge point 2
猜你喜欢
The problem of configuring opencv in qt5.13.2 is solved in detail
Chapter 2: try to implement a simple bean container
Ethtool principle introduction and troubleshooting ideas for network card packet loss (with ethtool source code download)
【无标题】
What if the DataGrid cannot see the table after connecting to the database
Ros2 - configuration development environment (V)
【软件测试】04 -- 软件测试与软件开发
An article was opened to test the real situation of outsourcing companies
2022 PMP project management examination agile knowledge points (7)
IPage can display data normally, but total is always equal to 0
随机推荐
Docker installs MySQL and uses Navicat to connect
U-Boot初始化及工作流程分析
M2dgr slam data set of multi-source and multi scene ground robot
氢氧化钠是什么?
并查集理论讲解和代码实现
2022年PMP项目管理考试敏捷知识点(7)
你心目中的数据分析 Top 1 选 Pandas 还是选 SQL?
[software testing] 04 -- software testing and software development
Concurrent programming - deadlock troubleshooting and handling
Brief description of inux camera (Mipi interface)
Machine learning Seaborn visualization
Import CV2, prompt importerror: libcblas so. 3: cannot open shared object file: No such file or directory
1290_FreeRTOS中prvTaskIsTaskSuspended()接口实现分析
[vscode] prohibit the pylance plug-in from automatically adding import
And play the little chestnut of dynamic agent
玩转gRPC—深入概念与原理
Simple operation of running water lamp (keil5)
Powermanagerservice (I) - initialization
The problem of configuring opencv in qt5.13.2 is solved in detail
HDU1231 最大连续子序列(分治or动规or双指针)