Update:
For a possible answer to your question using functions (the original question did not have a function), see here: Is there a way to write a bash function which aborts the whole execution, no matter how it is called?
(you can also update your question further to get better answers)
One possible solution would be using something like this for every line:
curl ... || exit
Of course, if you have multiple urls, you can encapsulte that in a function for example, or you could chain them this way:
curl ... && curl ... && ...
You can also break the current line using \
like this:
curl ... && \
curl ... && \
...
This also works because a script without explicit exit
statement should return the last set exit code, e.g. the one returned by the last executed curl command in this case.
Regarding the used operators:
a || b
Means: evaluate a
OR b
, and the ||
is logically applied to the return code of a
, so if a
returns 0
or something not 0
, b
will be executed anyway.
a && b
Means: execute a
AND b
, and the &&
is again logically applied to the return code of a
, so if a
returns 0
(=false), b
won't be executed as the evaluation will stop at that point, but if a
returns a value not 0
(=true), evaluation and thus execution will continue.
You can additionally combine this with subshells using parantheses ((
and )
) and other stuff to build some quite complex command chains, but I would advise to follow the KISS ("Keep it simple, stupid!") principle in case of shell scripts and better write everything on their own line, additionally commenting ( using #
), so you still know what the script does if you have to look at it a year later ;)
While these things have been the same on all the shells I've used so far, there can still be differences, but if you, like me, have bash on most machines, this might be interesting to you:
Bash Reference Manual