IIUC, вы можете соединить строки с ||
, если mongo
возвращает не -ноль при ошибке. Как описано вman bash
:
An OR list has the form
command1 || command2
command2 is executed if and only if command1 returns a non-zero exit status. The return status of AND and OR lists is the exit status of the last command executed in the list.
У меня нет mongo
здесь, но я могу выложить примерsucceeds.sh
:
#!/usr/bin/env sh
nonexistent-command || \
echo a || \
echo b || \
echo c
Выполнить:
$./succeeds.sh
./succedds.sh: line 3: nonexistent-command: command not found
a
Как видите, скрипт останавливается на a
, потому что это первая команда, которая завершилась успешно.