[Shell] on a command is completed before the next operation | shell script to determine whether the previous command executed successfully

shell script to determine whether the previous command executed successfully 

the shell using the symbol "$?" to display a command on the return value of success if it is 0 behalf of the Executive, the other for failure.
Combined to achieve the if-else statement to determine whether a command is executed successfully.

 

Scenario: If the clone success of the project, only to package work

Sample script:

echo "clone命令"
git clone -b <branchName> <gitAddress>

if [$? -ne 0]; then 
    echo "faild"
else
    echo "success"
fi

running result:

 

 

 

 

Reference documents:

Execution on multiple linux shell commands, in the successful implementation of the previous step before continuing to the next command command, and each step contains multiple command statement concise wording

shell script to determine whether the previous command executed successfully

Guess you like

Origin www.cnblogs.com/kaerxifa/p/11982784.html