In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the relevant knowledge of "what are the methods of Linux Shell script debugging mode". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope this article "what are the methods of Linux Shell script debugging mode" can help you solve the problem.
How to start writing a script
A script differs from other files in its first line, which contains #! (She-Bang-companion: define file type) and path name (interpreter path), informing the system that the file is a collection of commands that will be interpreted by the specified program (interpreter). The following is an example of the first line of different types of scripts:
#! / bin/sh [sh script] #! / bin/bash [bash script] #! / usr/bin/perl [perl Program] #! / bin/awk-f [awk script]
Note: if the script contains only a set of standard system commands without any internal Shell instructions, the first line or #! It can be removed.
How to execute Shell script in Linux operating system
The general syntax for invoking a script is:
$script name parameter 1. Parameter N
Another possible form is to explicitly specify the Shell on which the script will be executed, as follows:
$shell script name parameter 1. Parameter N
Example:
$/ bin/bash parameter 1... Parameter N [bash script] $/ bin/ksh parameter 1. Parameter N [ksh script] $/ bin/sh parameter 1. Parameter N [sh script]
For no #! As the first line, the script contains only the underlying system commands, as an example:
# script contains only the standard system command cd / home/$USERmkdir tmpecho "tmp directory created under / home/$USER"
Make it executable and run, as follows:
$chmod + x script name $. / script name method to enable Shell script debugging mode
Here are the main Shell script debugging options:
-v (short for verbose)-tells Shell to display all lines when reading the script, activating verbose mode. -n (noexec or no ecxecution abbreviation)-instructs Shell to read all commands without executing them. This option activates syntax checking mode. -x (xtrace or execution trace abbreviation)-tells Shell to display all executed commands and their parameters on the terminal. This option is to enable Shell trace mode.
1. Change the first line of the Shell script
The first mechanism is to change the first line of the Shell script, as follows, which starts script debugging.
#! / bin/sh option
Where the options can be one or more of the debugging options mentioned above.
2. Call Shell debugging option
The second is to start Shell with the following debugging option, which also opens the entire script debugging.
$shell option parameter 1. Parameter N
Example:
$/ bin/bash option parameter 1... Parameter N
3. Use the Shell built-in command set
The third method is to use the built-in command set to debug a given part of the Shell script, such as a function. This mechanism is important because it allows us to debug any Shell script. We can turn on debug mode using the set command as follows, where the options are all of the debug options mentioned earlier.
$set option
Enable debug mode:
$set-option
Disable debug mode:
$set + option
In addition, if we enable several debug modes in different parts of the Shell script, we can disable all debug modes at once, as follows:
Set-this is the end of the introduction to "what are the ways to debug Linux Shell scripts". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.