Home IT Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Linux Shell debugging     - C ++ Fundamentals study notes (Programming)

- Ubuntu 15.04 / CentOS 7.0 to set custom boot (Linux)

- Alternative methods of intrusion bundled executable file new thinking (Linux)

- Red Hat Enterprise Linux configuration VNC multi-user access methods (Linux)

- These days have been tossing in the Linux under the ASP.NET 5, on the next in the other operating systems in the ASP.NET 5 or. NET applications, in order to complete the MS VM (CoreCLR) run is not far Reach, the effect of the application.

Cur
(Server)

- Automatic batch resolve dependencies problem locally installed rpm package (Linux)

- How do you turn on and off IPv6 address on Fedora (Linux)

- CentOS installed JDK8 (Linux)

- 10 Linux in the passwd command examples (Linux)

- Java, on the dfile.encoding Systemproperty (Programming)

- To create a secure network firewall with iptables Under Linux (Linux)

- Generators and iterators in Python (Programming)

- Ubuntu Eclipse configuration Gtk + 2.0 libraries (Linux)

- Java class HashSet (Programming)

- RabbitMQ tutorial examples: the Hello RabbitMQ World Java realization (Linux)

- Spring + MyBatis Multi data source switching (Database)

- Zombie process under Linux (Linux)

- Installation Elementary OS Freya to do some settings (Linux)

- Several back door and log tool under Linux (Linux)

- Ubuntu 12.04 installed OpenCV 2.3.1, binary image (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:      
 
- Scala REPL Shell call (Programming)
- Linux iptables firewall and vsftpd to resolve the issue (Linux)
- Linux system package manager -RPM (Linux)
- Basic Tutorial: Linux novice should know 26 commands (Linux)
- C # and JavaScript arrays to re-summary (Programming)
- The best tools and techniques to find data on a Unix system (Linux)
- CentOS / Linux install VNC Server (Linux)
- Steps to build MPICH2 development environment on CentOS 6.4 (Linux)
- To setup Cocos2dx project under Ubuntu (Linux)
- Linux system on how to use rsync to synchronize data (Server)
- Configuring a Linux operating system against syn attack (Linux)
- HTML5 postMessage cross-domain data exchange (Programming)
- Simple and fast sorting (Programming)
- Read and write files efficiently from Apache Kafka (Server)
- Android start automatically and add and delete a desktop shortcut (Programming)
- The security configuration of Linux (Linux)
- MySQL DATE_FORMAT () function (Database)
- tar command to extract a file error: stdin has more than one entry (Linux)
- Linux environment variable settings methods and differences (Linux)
- Btrfs file system creation and their characteristics in Linux (Linux)
     
           
     
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.