Загрузка в VNCViewer на Raspberry Pi.

Вы можете записать это так:

if git branch -m $newrcName; then
    git push origin --delete rc
fi

Таким образом, вторая команда выполняется только тогда, когда первая команда завершается с кодом выхода 0, который указывает на успех.

Дополнительную информацию о ключевом слове if можно получить, запустив help if . Пример вывода из моей системы (Bash 4.3.46 (1) -release):

if: if COMMANDS; then COMMANDS; [ elif COMMANDS; then COMMANDS; ]... [ else COMMANDS; ] fi
Execute 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 is
executed 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 the
entire construct is the exit status of the last command executed, or zero
if no condition tested true.

Exit Status:
Returns the status of the last command executed.

Если вы хотите узнать код ошибки, вы можете прочитать его из $ ?. Bash сохраняет в этой переменной код выхода последней выполненной команды. Вы можете сохранить его в переменной, чтобы использовать его позже:

git branch -m $newrcName
BRANCH_EXIT_CODE=$?
echo "git branch -m $newrcName exit code was $BRANCH_EXIT_CODE"
# $? now contains the exit code of the preceding echo
if [ $BRANCH_EXIT_CODE -eq 0 ]; then
    git push origin --delete rc
fi
2
14.05.2015, 18:09
0 ответов

Теги

Похожие вопросы