numam-spdk/scripts/eofnl
Daniel Verkamp 1a37acda67 eofnl: check for extra trailing newlines
Enforce exactly one trailing \n, and fix all of the existing cases.

Change-Id: I6218e4700e90aeb647eaee78089530c79993c8c8
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
2016-10-11 13:30:33 -07:00

27 lines
349 B
Bash
Executable File

#!/usr/bin/env bash
# Make sure file has a trailing newline
f="$1"
if [ -z "$f" ]; then
echo "usage: $0 <file>"
exit 1
fi
if [ ! -f "$f" ]; then
exit 0
fi
if [[ $(tail -c1 "$f") ]]; then
echo "$f: No newline at end of file"
echo '' >> "$f"
exit 1
fi
if [[ ! $(tail -c2 "$f") ]]; then
echo "$f: Extra trailing newline"
exit 1
fi
exit 0