当前位置:网站首页>Shell script basic syntax
Shell script basic syntax
2022-07-05 07:53:00 【Group field】
Mac Under the computer Bash, yes Unix shell A kind of , Developers through shell Script middleware calls the system kernel , So it is necessary for Apple developers to learn .
1 Create and export
1-1 establish Shell file
command :touch hello.sh
1-2 Definition file declaration
#!/bin/bash
#!: Indicates the Convention mark , He will tell the system what kind of interpreter this script needs to execute , It is both a script embodiment .'#' notes , Be careful : stay Shell Script , No multi line gaze , Only single line comments .
echo “Hello world!”
1-3 perform Shell Script hello file
command :./hello.sh
View and modify file permissions
View command :ls -l hello.sh
Modify the order : chmod +x ./hello.sh
-rwxr-xr-x
1-4 Variable operating
- There should be no spaces in the assignment
name="Kenny"Can not writename = "Kenny"
Variable names must start with ‘a-z’ or ‘A-Z’ See the letter of , Read only variables cannot be modified , tastereadonly name - Delete variables
unset name - Special variables
${0}: File name${?}: Indicates the return value of the execution status of the previous command$#: Number of parameters$*: parameter list , Composite string[email protected]: parameter list$$: Go back to the current shell Conduct ID$!: Execute last instruction PID
1-5 String splicing 、 Intercept 、 Delete
- Splicing
#!/bin/bash
name='Andy'
age=100
sex=" male "
info=" full name :'${name}' Age :'${age}' Gender :'${sex}' "
echo ${info}
- Intercept
Variable name : start : end , result ’have’
name="I have a Dream"
result=${name:2:4}
echo ${result}
Find the length of the variable length=${#name}-1
The end position may not be written , To the end
name="I have a Dream"
result=${name:5:length-1}
echo ${result}
- Delete
# Grammar 1 :${ Variable name # Delete string Regular expressions }Delete from the first## Grammar II :${ Variable name ## Delete string Regular expressions }Delete from the last% Grammar 3 :${ Variable name % Delete string Regular expressions }Find the first of the specified characters , And delete all the previous characters ( Include yourself )%% Grammar 3 :${ Variable name %% Delete string Regular expressions }Find the last of the specified character , And delete all the previous characters ( Include yourself )
Delete range : Delete from left to right
#-> Indicates that the query direction is from left to right
%-> Indicates that the query direction is from right to left
Delete range : Delete from right to left
##-> Indicates that the query direction is from right to left
%%-> Indicates that the query direction is from left to right
Case a : Find the first of the specified characters , And delete all the following characters ( Include yourself )
# Look for the first one from the left , And delete all the previous characters ( Include yourself )
name="I have a Dream"
result=${name#*a}
echo ${result}
result
ve a Dream
## Look for the first one from the right , And delete all the previous characters ( Include yourself )
name="I have a Dream"
result=${name##*a}
echo ${result}
result
m
Case 2 : Find the first of the specified characters , And delete all the following characters ( Include yourself )
% Look for the first one from the right , And delete all the following characters ( Include yourself )
name="I have a Dream"
result=${name%a*}
echo ${result}
result
I have a Dre
%% Look for the first one from the left , And delete all the following characters ( Include yourself )
name="I have a Dream"
result=${name%%a*}
echo ${result}
result
I h
边栏推荐
- What is Bezier curve? How to draw third-order Bezier curve with canvas?
- Mlperf training v2.0 list released, with the same GPU configuration, the performance of Baidu PaddlePaddle ranks first in the world
- NSIS finds out whether the file exists and sets the installation path
- Altium Designer 19.1.18 - 隐藏某一个网络的飞线
- Oracle-触发器和程序包
- 如何进行导电滑环选型
- STM32 knowledge points
- Package ‘*****‘ has no installation candidate
- Distinction between heap and stack
- Let me teach you how to develop a graphic editor
猜你喜欢

mysql 盲注常见函数

Train your dataset with yolov4

UEFI development learning 3 - create UEFI program

Numpy——1.數組的創建

L'étude a révélé que le système de service à la clientèle du commerce électronique transfrontalier a ces cinq fonctions!

About the problem that MySQL connector net cannot be cleared in MySQL

Ten thousand words detailed eight sorting must read (code + dynamic diagram demonstration)

High end electronic chips help upgrade traditional oil particle monitoring

如何将EasyCVR平台RTSP接入的设备数据迁移到EasyNVR中?

Scm-05 basis of independent keyboard
随机推荐
C#,数值计算(Numerical Recipes in C#),线性代数方程的求解,LU分解(LU Decomposition)源程序
Win10 shortcut key
Altium designer 19.1.18 - clear information generated by measuring distance
MLPerf Training v2.0 榜单发布,在同等GPU配置下百度飞桨性能世界第一
2021-10-28
Beijing Winter Olympics opening ceremony display equipment record 3
"Source code interpretation" famous programmer TJ's only library
GPIO circuit principle of stm32
Summary of STM32 serial port sending and receiving data methods
研究發現,跨境電商客服系統都有這五點功能!
Pointnet++ classification practice
LED display equipment records of the opening ceremony of the Beijing Winter Olympics
Mlperf training v2.0 list released, with the same GPU configuration, the performance of Baidu PaddlePaddle ranks first in the world
[idea] common shortcut keys
Apple terminal skills
Linked list (establishment, deletion, insertion and printing of one-way linked list)
MySQL blind note common functions
solver. Learning notes of prototxt file parameters
Day01 markdown log entry tips
A series of problems in offline installation of automated test environment (ride)