Skip to content

Instantly share code, notes, and snippets.

@skehlet
Created April 9, 2018 18:42
Show Gist options
  • Save skehlet/a4742cf78c434a5c26d84728c58e0d47 to your computer and use it in GitHub Desktop.
Save skehlet/a4742cf78c434a5c26d84728c58e0d47 to your computer and use it in GitHub Desktop.
$ docker run --rm -it ubuntu bash
root@b327e1a0640b:/# function file_ends_with_newline() {
> [[ $(tail -c1 "$1" | wc -l) -gt 0 ]]
> }
root@b327e1a0640b:/#
root@b327e1a0640b:/# touch empty.txt
root@b327e1a0640b:/#
root@b327e1a0640b:/#
root@b327e1a0640b:/# file_ends_with_newline empty.txt && echo ends in newline || echo does NOT end in newline
does NOT end in newline
root@b327e1a0640b:/#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment