Linux - set -vx
Set command in Linux is used to set or unset values of shell options and positional parameters.
It has many useful options, and specifically, set -vx is very useful to debug a Linux script.
-v Print shell input lines as they are read.
-x Print commands and their arguments as they are executed.
To use this, simply put set -vx before an interested script line. Usually, I will put it at the top of my script to print out everything.
For example, you can use set -vx as follow script call test.sh
Executing the test.sh with
The output will be
It has many useful options, and specifically, set -vx is very useful to debug a Linux script.
-v Print shell input lines as they are read.
-x Print commands and their arguments as they are executed.
To use this, simply put set -vx before an interested script line. Usually, I will put it at the top of my script to print out everything.
For example, you can use set -vx as follow script call test.sh
#!/bin/bash
set -vx
export foo=$1
echo $foo
Executing the test.sh with
./test.sh hello
The output will be
export foo=$1
+ export foo=hello
+ foo=hello
echo $foo
+ echo hello
hello
Those line with + sign are evaluated value during execution
Reference: http://linuxcommand.org/lc3_man_pages/seth.html
Comments
Post a Comment