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?

Tsyvarev
  • 60,011
  • 17
  • 110
  • 153
sjain
  • 17
  • 4
  • 1
    Please see: [Aborting a shell script if any command returns a non-zero value](https://stackoverflow.com/questions/821396/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. – starball Nov 23 '22 at 06:46
  • You should edit to say (by tagging and by stating) exactly what shell scripting language you want and answer for. – starball Nov 23 '22 at 06:47

1 Answers1

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
Simon Chen
  • 51
  • 5