How to detect if a file has a UTF-8 BOM in Bash?
First, let’s demonstrate that head is actually working correctly: $ printf ‘\xef\xbb\xbf’ >file $ head -c 3 file $ head -c 3 file | hexdump -C 00000000 ef bb bf |…| 00000003 Now, let’s create a working function has_bom. If your grep supports -P, then one option is: $ has_bom() { head -c3 “$1” | … Read more