Home IT Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Linux Shell debugging     - To install and deploy Java applications under CentOS 6.5 (Linux)

- Linux and Unix systems really do network more secure (Linux)

- Install Ubuntu open source drawing program MyPaint 1.2.0 (Linux)

- MySQL dual master configuration (Database)

- Qt for file splitting and fusion gadgets (Programming)

- Linux simple commands (Linux)

- Oracle create user authorization and in PLSQL (Database)

- Build a super simple "hardware" firewall router (Linux)

- Linux permissions Detailed (Linux)

- Security of data to create a safe .mdb database (Linux)

- Ubuntu users to install household financial management tools HomeBank 5.0.0 (Linux)

- How Ubuntu Snappy Core 2 running on Raspberry Pi (Linux)

- System-level alias vs Oracle ADR functionality (Database)

- Linux log management make the system more secure (Linux)

- The Rabbitmq installation under CentOS 6.4 (Linux)

- HA-Federation-HDFS + Yarn cluster deployment (Server)

- DRBD switchover (Server)

- Android studio multi-channel ultra-compact version of the package (Programming)

- Linux operating system boot process analysis (Linux)

- CentOS 6 compiling httpd-2.4.10 (Server)

 
         
  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:      
 
- PLSQL Developer synchronization table tools (Database)
- History of the most complex validation e-mail address regular expression (Linux)
- Learn to read the source code of vmstat (Linux)
- Web database security tips (Linux)
- Android LayoutInflater source parsing (Programming)
- To install and deploy Java applications under CentOS 6.5 (Linux)
- Linux (Ubuntu) How iptables port mapping (Server)
- Systemd on RHEL7 (Linux)
- CentOS7 minimized installation can not find the 'ifconfig' command - Repair Tips (Linux)
- Tmux Crash Course: Tips and adjustment (Linux)
- grep command Series: How to Use the grep command in Linux / UNIX (Linux)
- Unsafe reboot start (Linux)
- MySQL 5.6 master-slave replication configuration (Database)
- Oracle table space rename and delete table space (Database)
- Linux System Getting Started Tutorial: permission to permanently modify the USB device in Linux (Linux)
- Linux create and delete user step (Linux)
- Linux CentOS configuration SVN + SVN hook (Server)
- Mac OS X Server installation and application (Linux)
- MongoDB learning Notes (2) basic connection example of -Nodejs and MongoDB (Database)
- How to use jgit to manage Git submodule (Linux)
     
           
     
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.