Änderungen

Aus Hackerspace Ffm
Wechseln zu: Navigation, Suche

DCEM's bash script howto

825 Byte hinzugefügt, 09:32, 24. Mär. 2020
Add Fail fast section (by SublimeText.Mediawiker)
This way it is easy to see what customisations are intended/needed.
 
=== Fail fast ===
I think it is a good idea to have a script stop as soon as any error appers.
 
[https://codeinthehole.com/tips/bash-error-reporting/ Bash error reporting - by David Winterbottom] promotes a nice concept which I modiefied for better readability.
 
<nowiki>
#!/bin/bash
set -o nounset # treat unset variables as an error when substituting
set -o errexit # exit immediately if a command exits with a non-zero status
set -o pipefail # the return value of a pipeline is the status of
# the last command to exit with a non-zero status,
# or zero if no command exited with a non-zero status
 
function print_error {
read line file <<<$(caller)
echo "An error occurred in line $line of file $file:" >&2
sed "${line}q;d" "$file" >&2
}
trap print_error ERR</nowiki>
=== using here-documents ===
610
Bearbeitungen