0

I want to write a shell script in which am going to use cmake build:

cmake ..
cmake --build .

After these 2 statements more statements are to be added in the script. But if the cmake build fails the shell script should exit. Is there any way to achieve this?

2
  • 1
    Please see: Aborting a shell script if any command returns a non-zero value. The question post shows how to exit if a specific command fails, and the answer shows how to exit if any command in a script fails. Commented Nov 23, 2022 at 6:46
  • You should edit to say (by tagging and by stating) exactly what shell scripting language you want and answer for. Commented Nov 23, 2022 at 6:47

1 Answer 1

0

try add set -e in front of the script
bash manual: https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html
but it should also work with sh/zsh

#!/usr/bin/sh
set -e

echo foo
false
echo bar
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.