当前位置:网站首页>Shell programming core technology "four"
Shell programming core technology "four"
2022-07-04 19:24:00 【Wu_ Candy】
The content shared today is similar to Shell Programming core technology 《 3、 ... and 》 It's linked , It needs to be read together .
function
Next , We package it into a tester_level function , After having functions, they can be called at any time during the execution process to realize function encapsulation and logic reuse .
You can see from the picture above , call test_001.sh Script and pass in a parameter :java, It didn't output what we expected java auto tester, The reason is that only defining functions will not be implemented , For example, no relevant information is output at this time auto tester result .
And we run tester_level Function and will 2 Pass parameters to it , here 2 Is the second parameter of the script , But it is tester_level First argument to function .
Execute the script , Pass in a parameter java, No display , One more python Still no response , Until incoming python java After two parameters , Just output java auto tester, because tester_level The second parameter of the whole script is received .
Permission bit execution Shell Script
Through the demonstration of the previous case, we have mastered the use sh Execute the script , But if we Do not want to use sh Execute the script , If you want the system to parse automatically , It can be realized by weighted limit .
First of all to see test_001.sh What is the current permission bit of , You can use commands :ls -l /tmp/test_001.sh, As shown in the figure above , It can be found that there is no x, That is, there is no executable permission .
When we directly enter the command :/tmp/test_001.sh, namely test_001.sh When the full path of the file is , Wrong presentation :Permission denied No execution permission .
As shown in the figure above , Use command :chmod +x /tmp/test_001.sh Add executable permissions to files .
As shown in the figure above , When no document is given test_001.sh When adding executable permissions to a file , Direct use command :/tmp/test_001.sh It's a newspaper permission denied Wrong , But when you add executable permissions to the file , Use the command again :/tmp/test_001.sh When executing a script , It can be executed successfully , No report error .
add to PATH Variable fast execution Shell Script
If test_001.sh The full path of the file is very long , Such as /user/candy/python/shell/project_person_tmp/test_001.sh, We want to execute test_001.sh file , Follow the method described above , Need to enter test_001.sh The full path of the file can be executed , This is too complicated , Remember clearly every time you execute test_001.sh The full path of the file and enter , Is there a simpler way , If you only enter the file name :test_001.sh You can run the script directly ? The answer is yes .
The solution is : take /tmp This path adds to PATH variable , Enter test_001.sh If the command is executed directly, there will be no more errors .
Shell Debug during script execution
When our Shell The script is wrong , How to debug during execution ?
As shown in the figure above , have access to sh -x command , It can print every command line of the current script when the script is running , When the script goes wrong, you can know which line went wrong , It passes by + The output at the beginning shows which line is currently being executed Shell Code , With it, debugging becomes very convenient .
Friendship tips :“ The way of immeasurable testing ” Original works , Welcome to exchange , It is forbidden for a third party to reprint the article without displaying its source .
边栏推荐
- Learning path PHP -- phpstudy "hosts file does not exist or is blocked from opening" when creating the project
- 2022-07-04:以下go语言代码输出什么?A:true;B:false;C:编译错误。 package main import 'fmt' func
- Nature microbiology | viral genomes in six deep-sea sediments that can infect Archaea asgardii
- A method of using tree LSTM reinforcement learning for connection sequence selection
- Torchdrug tutorial
- PB的扩展DLL开发(超级篇)(七)
- 技术分享 | 接口测试价值与体系
- Mxnet implementation of googlenet (parallel connection network)
- 【机器学习的数学基础】(一)线性代数(Linear Algebra)(上+)
- 26. 删除有序数组中的重复项 C#解答
猜你喜欢

千万不要只学 Oracle、MySQL!

Go microservice (II) - detailed introduction to protobuf

Build your own website (15)

One question per day (2022-07-02) - Minimum refueling times

从实时应用角度谈通信总线仲裁机制和网络流控

英特尔集成光电研究最新进展推动共封装光学和光互连技术进步

Wanghongru research group of Institute of genomics, Chinese Academy of Agricultural Sciences is cordially invited to join

大div中有多个div,这些div在同一行显示,溢出后产生滚动条而不换行

升级智能开关,“零火版”、“单火”接线方式差异有多大?

奥迪AUDI EDI INVOIC发票报文详解
随机推荐
PB的扩展DLL开发(超级篇)(七)
The CDC of sqlserver can read the data for the first time, but it can't read the data after adding, deleting and modifying. What's the reason
sqlserver的CDC第一次查询的能读取到数据,但后面增删改读取不到,是什么原因
Use canal and rocketmq to listen to MySQL binlog logs
Caché JSON 使用JSON适配器
测试工程师如何“攻城”(上)
Leetcode fizzbuzz C # answer
Qt实现界面滑动切换效果
基于C语言的菜鸟驿站管理系统
The 15th youth informatics competition in Shushan District in 2019
redis分布式锁的8大坑总结梳理
prometheus安装
神经网络物联网平台搭建(物联网平台搭建实战教程)
Li Chi's work and life summary in June 2022
php伪原创api对接方法
Safer, smarter and more refined, Chang'an Lumin Wanmei Hongguang Mini EV?
ftp、sftp文件传输
Guys, for help, I use MySQL CDC 2.2.1 (Flink 1.14.5) to write Kafka and set
The latest progress of Intel Integrated Optoelectronics Research promotes the progress of CO packaging optics and optical interconnection technology
2022CoCa: Contrastive Captioners are Image-Text Fountion Models