I've saved files with different encodings using TextEdit. After closing the file, with a vim editor, I open the file and type the following to test for the existence of a byte order mark:
:setlocal bom?
no bom is detected for any encoding.
This script seems to directly create BOMs ok.
#!/usr/bin/env bash
printf '\xEF\xBB\xBF' > withBom.txt
But, I'd like to use a more reliable technique than that to create files with BOM. I don't understand what is going on with TextEdit.