Home IT Linux Windows Database Network Programming Server Mobile  
  Home \ Programming \ Linux Shell debugging     - Big Data Common Glossary (Linux)

- ORA-600 [kcbz_check_objd_typ] Error Handling (Database)

- Linux system components Detailed log (Linux)

- 22 Port weak passwords and SSH connection program of the Linux server (Linux)

- Getting the Linux shell expr use (Programming)

- sed and awk in shell usage and some examples (Linux)

- Analysis examples: Intrusion Response Linux platform Case (Linux)

- CKEditor + SWFUpload achieve a more powerful editor (Linux)

- OpenStack image production in the CentOS 6.2 (Linux)

- Make command Detailed Tutorial (Programming)

- ARM constant expression (Programming)

- Linux operating system Study Notes (Linux)

- VirtualBox virtual machine to install Linux (Linux)

- Java to achieve local fileCopy (Programming)

- Access clipboard content across multiple vim instances in a terminal (Linux)

- 10 practical Java programming technology (Programming)

- Linux user login ban (Linux)

- Recovery from MySQL master data consistency summary (Database)

- Use Makeself Create installation file (Linux)

- The best tools and techniques to find data on a Unix system (Linux)

  Linux Shell debugging
  Add Date : 2017-08-31      
  Debugging Shell procedure is added when you run the program through the debugging option, or join the relevant statements in the script, so that shell program shows some reference for "debugging information" in the implementation process. Of course, users can also place in the shell program to add some echo command is used to debug and trace.

Method One: Add the debug option when you run the script:

[Usage] bash - Options ./shellScript.sh
Several common debugging options are as follows:
        -e: If a command returns a non-zero exit status value (failure), then exit.
        -n: execute the script just does not need to check the syntax structure, syntax returns all error messages.
        -u: substitution when the variable is not set is regarded as an error.
        -v: When the shell reads input rows to display them.
        -x: When executing commands, the commands and their parameters are displayed.

Method 2: In the script debugger command set:

[Usage] set - commonly used options above options, set + option #set command
        Shell procedures used to internally - in the form of "set option" references and "set + option" will be the selection function disabled. If you want to use a certain part of the program of choice, you can use the above two statements this portion surrounded.

(1) variable is not set exit (-u) and exit (-e) immediately

Variable is not set exit feature allows the user to check all the variables, if you reference an unassigned variables Shell terminate the execution of the program. Shell is usually allowed to use variable is not set, in this case, the value is null variable. If the variable is not set exit options, once the use is not set variables displays an error message and terminates the program. Variable is not set for the exit option -u.

When Shell is running, if the encounter does not exist or is not executed command, redirect command fails or abnormal termination, etc., if not redirect the error message will be displayed on the terminal screen, the program will continue and Shell carried out. To force Shell program ends immediately when an error occurs, you can use the -e option to execute Shell program terminates immediately.

(2) Shell program track (-v or -x)

The main method is to use a program debugging Shell Shell command interpreter -v or -x option to trace program execution. -v option enables Shell during the execution of the program, to each command it reads rows displayed and the -x option so that each command Shell in the implementation of the program to execute it with the first line + with a command name is displayed. And put every variable and the value of the variable taken also displayed. Therefore, the main difference is that: before executing the command line without -v, the command line shows the original content, and when -v is showing through the command line after the replacement content.



#! / Bin / bash

iftest () {
    if [$ # -ne 1]
        echo "Usage: $ 0 dir"
        exit 1
  # Set -v or set -x # If you select the second method, you uncommented, and select one of the set command

    if [-d "$ 1"]
        ls -l $ 1
        exit 0

    # Set + v or set + x # If you select the second method, you uncommented, and select one of the set command

    echo "Warn: $ 1 is not a directory!"
    exit 2

iftest ..

A method of operating results:

bash -v ./iftest.sh

bash -x ./iftest.sh

Note: $ 1 $ 1 = # = ..

Method Two operating results:

Cancel iftest.sh program notes, and select only the set -x command and set + x, indicating only the second if..fi statement block for debugging.

- How to use GRUB2 files directly from the hard disk to run ISO (Linux)
- JavaScript function closures Quick Start (Programming)
- Git uses a standard process (Linux)
- Getting Started with Linux system to learn: how to check memory usage of Linux (Linux)
- Linux kernel network subsystem analysis (Programming)
- CentOS7 install JDK (Linux)
- ImportTsv-HBase data import tool (Database)
- The FreeBSD zfs: failed with error 6 Error Resolution (Linux)
- Ubuntu Server security risk checks (Linux)
- Modifying the system registry protection server security (Linux)
- C ++ How to determine the types of constants (Programming)
- Android code performance optimization tips (Programming)
- A summary of Java multi-threaded programming - acquaintance multithreading (Programming)
- Use Vagrant build cross-platform development environment for Python (Server)
- Use Bash script write CVS version control (Server)
- Oracle 12c of the auto-increment Identity Columns (Database)
- Use Visual Studio to compile and use WinGDB remote debugging embedded Linux programs (Programming)
- The simple multi-threaded Python (Programming)
- Linux Task Scheduler (at, crontab) (Linux)
- Linux filtration empty file command summary (Linux)
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.