How can I modified this script to conditionally execute ${deleteOldBranchRemote} when there is no error executing ${getRename}?Now_hourly=$(date +%d%b%H%M)#echo $Now_hourlynewrcName=rc$Now_hourly#rename rc to the new namegetRename=git branch -m $newrcName#Delete the old-name remote branchdeleteOldBranchRemote=git push origin --delete rc${getRename}#if getRename has error then do not execute the following line#if [ $noErrorSomehowIneedToCheckForErrors ]  #then    ${deleteOldBranchRemote}#fi
Checking for errors in bash script
bash;git
You can write it like this:if git branch -m $newrcName; then    git push origin --delete rcfiSo the second command is only executed when the first command finishes with an exit code of 0 which indicates success.You can get more info about the if keyword by running help if. Example output from my system (Bash 4.3.46(1)-release): if: if COMMANDS; then COMMANDS; [ elif COMMANDS; then COMMANDS; ]... [ else COMMANDS; ] fiExecute commands based on conditional.The `if COMMANDS' list is executed.  If its exit status is zero, then the`then COMMANDS' list is executed.  Otherwise, each `elif COMMANDS' list isexecuted in turn, and if its exit status is zero, the corresponding`then COMMANDS' list is executed and the if command completes.  Otherwise,the `else COMMANDS' list is executed, if present.  The exit status of theentire construct is the exit status of the last command executed, or zeroif no condition tested true.Exit Status:Returns the status of the last command executed.If you want to know the error code you can read it from $?. Bash stores the exit code of the last executed command in this variable. You can store it in a variable to use it later:git branch -m $newrcNameBRANCH_EXIT_CODE=$?echo git branch -m $newrcName exit code was $BRANCH_EXIT_CODE# $? now contains the exit code of the preceding echoif [ $BRANCH_EXIT_CODE -eq 0 ]; then    git push origin --delete rcfi