Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
ゼロ以外のステータスを返す最初のコマンドで bash スクリプトを終了させる方法はありますか?
私はそれを次のようにチェーンできることを知っています&&:
&&
cd /stuff && echo 'what's up' && ....
別の方法はありますか?
はい、これはシバンの後にスクリプトの先頭に追加するだけで簡単です:
set -e
必要に応じて(コードの一部のみ)これを停止できます
set +e
またはシバンで:
#!/bin/bash -e
または次のようにスクリプトを呼び出します。
bash -e script.bash