Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Debugging skills of shell script

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

0. Standard format of professional scripts

Function 1 function 2main function main $*

1. Use the dos2unix command to convert scripts developed under windows

Dos2unix is not installed by default and can be installed by yum

# dos2unix web_jk.shdos2unix: converting file web_jk.sh to UNIX format...

2. Use echo command to debug

3. Debug using bash command parameters

# sh [- nvx] scripts.sh-n does not execute the script, only queries whether there is a problem with the script syntax and gives an error prompt. -v when executing the script, first output the contents of the script to the screen and then execute the script. If there is an error, it will also give an error prompt. -x * * displays the contents and output of the executed script to the screen for debugging super useful parameters!

4. Debug part of the script using set command parameters

-n read commands but do not execute-v display all lines read-x * * displays all commands and their parameters

Write in the script:

Set-xdiff / tmp/a.txt.ori / tmp/a.txtset + x

Tip:

Turn on the debugging function through the set-x command, and turn off the debugging function through set + x

5. Habits

The most important thing is to be proficient in syntax, coding habits and programming ideas, nip errors in the bud, reduce debugging burden and improve efficiency.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report