Beware that some shells don't support changing the locale during runtime (despite this is required by POSIX).
Solution that should generally work without changing the locale
While the above should work with any (except newline or null) byte as sentinel value, it can be made easier, without changing the locale:
Using . or / should be generally fine, as POSIX requires:
- “The encoded values associated with
<period>,<slash>,<newline>, and<carriage-return>shall be invariant across all locales supported by the implementation.”, which means that these will have the same binary represenation in any locale/encoding. - “Likewise, the byte values used to encode
<period>,<slash>,<newline>, and<carriage-return>shall not occur as part of any other character in any locale.”, which means that the above cannot happen, as no partial byte sequence could be completed by these bytes/characters to a valid character in any locale/encoding. (see 6.1 Portable Character Set)
The above does not apply to other characters of the Portable Character Set.