当前位置:网站首页>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 .
边栏推荐
猜你喜欢
随机推荐
添加命名空间声明
读写关闭的channel是啥后果?
In flinksql, in addition to data statistics, is the saved data itself a state
Caché WebSocket
建立自己的网站(15)
神经网络物联网是什么意思通俗的解释
Scala basic tutorial -- 15 -- recursion
Li Chi's work and life summary in June 2022
国元期货是正规平台吗?在国元期货开户安全吗?
Technology sharing | interface testing value and system
[uniapp] uniapp development app online Preview PDF file
Send and receive IBM WebSphere MQ messages
876. 链表的中间结点
Unity给自己的脚本添加类似编辑器扩展的功能案例ContextMenu的使用
Basic tutorial of scala -- 16 -- generics
Download the first Tencent technology open day course essence!
Qt实现界面滑动切换效果
Pb extended DLL development (super chapter) (VII)
LeetCode 赎金信 C#解答
Wireshark网络抓包