Home IT Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Linux Shell debugging     - Use ISO document production OpenStack used CoreOS mirror (Linux)

- About Linux backdoor (Linux)

- CentOS source installation GitLab Chinese Version (Server)

- Justniffer installed on Ubuntu 15.04 (Linux)

- Sniffer Linux Environment (Linux)

- Ora-1092: OPI colleague K aborting process --- killed by OO Well killer (Database)

- Linux kernel log --dmesg (Linux)

- The correct way of logical backup mysqldump (Database)

- OpenSSH server configuration file for each Common Definition (Server)

- Oracle bug Ora-04043 (Database)

- Use scripts easily install the latest Linux kernel in Ubuntu (Linux)

- Vim copy and paste register (Linux)

- Tsung first test installation (Linux)

- ACL permissions Linux command (Linux)

- Oracle inline view updates problems encountered (Database)

- Linux Command study manual - GPG command (Linux)

- I use the desktop environment in GNU / Linux combination tool (Linux)

- Use apt-p2p up a local Debian package cache (Server)

- High-performance JavaScript loaded and executed (Programming)

- OpenStack package problems and solutions under CentOS6 (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.

[example]

./iftest.sh:


#! / Bin / bash

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

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

    # 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.

./iftest.sh
     
         
       
         
  More:      
 
- Awk include binding capacity larger than the specified size of all files directory (Linux)
- Help you make Git Bisect (Linux)
- MySQL 5.7.9 source compiler installation instructions (Database)
- Hadoop connection failed or stuck processing (Server)
- Manual cleaning Oracle audit records (Database)
- Android working with Volley Comments (Programming)
- How to implement Linux host Telnet SSH password Free (Server)
- Formatted output printf command (Programming)
- Ceph Source Analysis: Network Module (Server)
- VirtualBox 4.3 Can not open a new task for a virtual computer solution (Linux)
- Deep understanding of C # generics (Programming)
- Use Vagrant up a local development environment tutorials (Server)
- Automatic batch resolve dependencies problem locally installed rpm package (Linux)
- Using shell users or virtual users to login to pureftpd (Linux)
- Mind mapping software installed in CentOS 7 in XMind (Linux)
- The most concise explanation of JavaScript closures (Programming)
- Build Python3.4 + PyQt5.3.2 + Eric 6.0 development platform Ubuntu 14.04 (Server)
- Linux shell scripts bubble sort (Programming)
- VirtualBox install Windows 8.1 has encountered an error 0x000000C4 solutions (Linux)
- To install OwnCloud 7.0.4 under Ubuntu (Linux)
     
           
     
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.