当前位置:网站首页>Introduction to shell programming
Introduction to shell programming
2022-07-07 10:50:00 【Taylor lance】
1、realpath Get file absolute path
[email protected]:~/crystalmedia/scripts$ realpath activeMq_docker.sh
/home/kylin/crystalmedia/scripts/activeMq_docker.sh
[email protected]:~/crystalmedia/scripts$
2、if sentence
if Mainly pay attention to the space ,if And [ then [] A space before and after
if [ ! -f "${filename}" ]
then
echo "File '${filename}' NOT exists!"
exit 1
fi
Or this way of writing
if [ ! -f "${filename}" ];then
echo "File '${filename}' NOT exists!"
exit 1
fi
remarks :
Basically the same as other scripting languages . There's no big difference . But here's the thing .[] The conditions inside .
1、 String judgment
str1 = str2 When two strings have the same content 、 Length is true
str1 != str2 Dangchuang str1 and str2 It's true when you don't wait
-n str1 When the length of the string is greater than 0 Time is true ( The string is not empty )
-z str1 When the length of the string is 0 Time is true ( Empty string )
str1 Dangchuang str1 If it's not empty, it's true
2、 The judgment of numbers
int1 -eq int2 It is true that two numbers are equal
int1 -ne int2 Two numbers are not equal to true
int1 -gt int2 int1 Greater than int2 It's true
int1 -ge int2 int1 Greater than or equal to int2 It's true
int1 -lt int2 int1 Less than int2 It's true
int1 -le int2 int1 Less than or equal to int2 It's true
3、 Judgment of documents
-r file User readable as true
-w file Users can write true
-x file User executable is true
-f file The file is normal and the file is true
-d file File is true directory is true
-c file File is character special file is true
-b file Files are blocks, special files are true
-s file The file size is not 0 Time is true
-t file When file descriptor ( The default is 1) True when the specified device is a terminal
4、 Complex logical judgment
-a And
-o or
! Not
3、pushd and popd
pushd and popd It is to operate on a directory stack , and dirs Is to display the contents of the directory stack . The directory stack is a stack structure that stores directories , The current directory is always stored at the top of the stack structure ( Here we can see further from below ).
dirs There are two commonly used parameters :
Options
meaning
-p
Each line shows a record
-v
Each line shows a record , At the same time, show the record in the stack index
-c
Empty the directory stack
There is only one directory in the directory stack ( Of course, at the top of the stack ), Is the current directory . After switching directories , The directory in the stack also changes . adopt -c Option can clear other directories in the directory stack except the current directory , Because the directory stack in the above example only contains the current directory , So there's no change .
Every time pushd After the command is executed , By default, a dirs Command to display the contents of the directory stack .pushd There are mainly the following usages :
pushd Catalog
pushd If you use it directly after the directory , Will switch to the directory and put the directory on the top of the directory stack .( Always remember , The current directory is always stored at the top of the directory stack . If the current directory changes , Then the top element of the directory stack must also change ; In turn, , If the element at the top of the stack changes , Then the current directory must have changed .) Here is an example :
[email protected]:~$ pushd crystalmedia/test/
~/crystalmedia/test ~
[email protected]:~/crystalmedia/test$ pushd /opt/
/opt ~/crystalmedia/test ~
[email protected]:/opt$ popd
~/crystalmedia/test ~
[email protected]:~/crystalmedia/test$ popd
~
[email protected]:~$
From the above example we can see that , use pushd To replace cd It's very useful .
pushd and popd Of the two +n
pushd +n
pushd +n Switch to the... In the directory stack n A catalog ( there n Namely dirs -v Command displayed index), And push the directory to the top of the stack in a stack loop .
popd +n
Put the... In the directory stack n Elements delete ( there n It's an order dirs -v Displayed directory index)
We usually don't want to dirs Show it , So pass
pushd Catalog >/dev/null
边栏推荐
- Basic introduction of yarn and job submission process
- 2022年7月10日“五心公益”活动通知+报名入口(二维码)
- The gun startles the dragon, and the crowd "locks" Zhou Zhi
- 555 circuit details
- 一些线上学术报告网站与机器学习视频
- 2022.7.6DAY598
- 软考信息处理技术员有哪些备考资料与方法?
- IDA中常见快捷键
- Mendeley -- a free document management tool that automatically inserts references into papers
- Use load_ decathlon_ Datalist (Monai) fast loading JSON data
猜你喜欢

打算参加安全方面工作,信息安全工程师怎么样,软考考试需要怎么准备?

香橙派OrangePi 4 LTS开发板通过Mini PCIE连接SATA硬盘的操作方法

Some superficial understanding of word2vec
![1321: [example 6.3] deletion problem (noip1994)](/img/bd/b605ec7b901079a9ebaca446fad7fb.png)
1321: [example 6.3] deletion problem (noip1994)

Using tansformer to segment three-dimensional abdominal multiple organs -- actual battle of unetr

What does intermediate software evaluator test

优雅的 Controller 层代码

使用Tansformer分割三维腹部多器官--UNETR实战

ThreadLocal会用可不够

【推荐系统 01】Rechub
随机推荐
【机器学习 03】拉格朗日乘子法
How to prepare for the advanced soft test (network planning designer)?
[machine learning 03] Lagrange multiplier method
SQL Server 知识汇集11 : 约束
Multisim -- software related skills
Common shortcut keys in IDA
How to get hardware information in unity
[detailed explanation of Huawei machine test] tall and short people queue up
无法打开内核设备“\\.\VMCIDev\VMX”: 操作成功完成。是否在安装 VMware Workstation 后重新引导? 模块“DevicePowerOn”启动失败。 未能启动虚拟机。
[STM32] solution to the problem that SWD cannot recognize devices after STM32 burning program
简单易修改的弹框组件
Those confusing concepts (3): function and class
[actual combat] transformer architecture of the major medical segmentation challenges on the list --nnformer
555 circuit details
【STM32】实战3.1—用STM32与TB6600驱动器驱动42步进电机(一)
The mobile terminal automatically adjusts the page content and font size by setting rem
P1223 queuing for water /1319: [example 6.1] queuing for water
关于easyflash v3.3使用过程的记录
TypeScript 接口继承
书签整理-程序员常用网站导航