shell bash

  • the shell assigns its exit code to the $? environment variable. The $? variable is how we usually test whether a script has succeeded or not in its execution.

syntax

set -x

​ 1. Debugging: When you’re trying to troubleshoot a script, set -x helps you see exactly what commands are being executed and in what order.

​ 2. Selective Debugging: You can use set -x and set +x around specific parts of your script to narrow down the problematic sections.

1
2
3
4
5
6
7
8
9
10
#!/bin/bash

echo "This is a normal message"

set -x # Start debugging from this point
name="John"
echo "Hello, $name"

set +x # Stop debugging after this point
echo "Debugging mode is now off"

output:

1
2
3
4
5
This is a normal message
+ name=John
+ echo 'Hello, John'
Hello, John
Debugging mode is now off

point

  • (cd third-party && ...) 这样的语法,这是一个命令替换,它实质上是先临时改变到 third-party 目录执行里面的命令,然后脚本会继续在原先的目录中执行。