Created
April 12, 2018 18:57
-
-
Save yaauie/59fae7c13972135fae7be6aad46ddb9e to your computer and use it in GitHub Desktop.
Ensure Trailing Newline: ensures that the given plaintext file ends with a newline character, appending in-place only if it is missing.
This file contains 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
#!/usr/bin/env bash -e | |
# | |
# Ensure Trailing Newline: ensures that the given plaintext file ends with a | |
# newline character, appending in-place only if it is missing. | |
# | |
# Portable on POSIX-based or POSIX-compatible systems, as it uses POSIX-standard | |
# invocations of `wc`, `tail`, and `echo`. | |
# | |
# Copyright 2018 Ry Biesemeyer | |
# | |
# Made available under the [MIT license](https://opensource.org/licenses/MIT) | |
TARGET="${1:?USAGE: $(basename $0) <filename>}" | |
if [ $(tail -c1 "${TARGET}" | wc -l) -eq 0 ]; then | |
echo >> "${TARGET}" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment