当前位置:网站首页>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 .
边栏推荐
猜你喜欢
随机推荐
2019年蜀山区第十五届青少年信息学竞赛
【uniapp】uniapp开发app在线预览pdf文件
[发布] 一个测试 WebService 和数据库连接的工具 - DBTest v1.0
Scala basic tutorial -- 17 -- Collection
C language printing exercise
Perfect JS event delegation
从实时应用角度谈通信总线仲裁机制和网络流控
性能优化之关键渲染路径
Learning path PHP -- phpstudy "hosts file does not exist or is blocked from opening" when creating the project
Summary and sorting of 8 pits of redis distributed lock
基于NCF的多模块协同实例
资料下载 丨首届腾讯技术开放日课程精华!
Unity editor extends C to traverse all pictures in folders and subdirectories
Scala基础教程--19--Actor
Scala basic tutorial -- 19 -- actor
每日一题(2022-07-02)——最低加油次数
Detailed explanation of issues related to SSL certificate renewal
大div中有多个div,这些div在同一行显示,溢出后产生滚动条而不换行
My colleagues quietly told me that flying Book notification can still play like this
问下各位大佬有用过cdc直接mysql to clickhouse的么