3 ms·
> Is that possible with shell [...] #!/bin/bash set -eu <actual work> Explained: -e Exit immediately if a simple command exits with a non-zero status,
by emilburzo 11y ago
> Is that possible with shell [...]
#!/bin/bash
set -eu
<actual work>
Explained:
-e Exit immediately if a simple command exits with a non-zero status, unless
the command that fails is part of an until or while loop, part of an
if statement, part of a && or || list, or if the command's return status
is being inverted using !. -o errexit
-u Treat unset variables as an error when performing
parameter expansion. An error message will be written
to the standard error, and a non-interactive shell will exit. -o nounset
Worth a read: http://ss64.com/bash/set.html http://ss64.com/bash/set.html
- mioelnir 11y agoThere is also the variable-expansion abort, even with optional custom error message: "${VAR:?Error message goes here}" Will exit2 if VAR is unset or the empty string. Or, which I often use, build the path you want to delete, call realpath on it - then check if your base directory you never ever have any business leaving is a prefix string of the realpath resolved path. This still allows to symlink stuff into subdirectories but will catch if something resolves suddenly all over the place.