In bash how do we make the script to automatically exit if a command line return code is not zero. For example:
#!/bin/bash
cd /something_something
mv file_a /somedir/file_a # this produce an error
echo $? # This produce a non-zero output
echo "We should not continue to this line"
I know we can debug bash script with #!/bin/bash -x
but sometime the script is too long, it run so fast, and we missed important error.
And I don't want to keep writing
[[ $? -ne 0 ]] && run next_command