Created
August 28, 2021 13:41
-
-
Save casperklein/4aa8a7fa28ef7ab50149df7f25914759 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # wrapper for 'sed -i': fail if file was not modified by sed | |
| set -ueo pipefail | |
| HASHTOOL="sha1sum" | |
| if [ $# -lt 1 ]; then | |
| echo "Error: No file given." | |
| echo | |
| exit 1 | |
| fi >&2 | |
| # get last argument | |
| FILE=${*: -1} | |
| OLD=$($HASHTOOL "$FILE") | |
| sed "$@" | |
| NEW=$($HASHTOOL "$FILE") | |
| # fail if file was not modified | |
| if [ "$OLD" == "$NEW" ]; then | |
| echo "Error: sed $*" | |
| exit 1 | |
| fi >&2 | |
| exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment