Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Post History

50%
+0 −0
Q&A Temporarily making \u escapes use a different encoding on the command line

I don't think you can persuade Bash to use non-UTF-8 characters internally—I expect much of its code assumes that strings are ASCII-compatible. So $'\u00FF' will always translate, inside Bash, to t...

posted 4d ago by r~~‭  ·  edited 4d ago by r~~‭

Answer
#2: Post edited by user avatar r~~‭ · 2025-05-31T17:19:04Z (4 days ago)
  • I don't think you can persuade Bash to use non-UTF-8 characters internally—I expect much of its code assumes that strings are ASCII-compatible. So `$'\u00FF'` will always translate, inside Bash, to the UTF-8 byte sequence `c3 bf`, and that's what
  • If you want to take a UTF-8 byte sequence that Bash (or another utility) has produced and translate it to UTF-16, use iconv:
  • ```
  • $ printf %s $'\u1234\u00FF' | iconv -t utf-16 | xxd -g2 -e
  • 00000000: feff 1234 00ff ..4...
  • ```
  • As you can see, you'll have to contend with the `\uFEFF` BOM if you do this.
  • Note that this will barf if you give it `$'\xFF'`, which isn't valid UTF-8. Mixing the two encodings is a recipe for sadness.
  • I don't think you can persuade Bash to use non-UTF-8 characters internally—I expect much of its code assumes that strings are ASCII-compatible. So `$'\u00FF'` will always translate, inside Bash, to the UTF-8 byte sequence `c3 bf`.
  • If you want to take a UTF-8 byte sequence that Bash (or another utility) has produced and translate it to UTF-16, use iconv:
  • ```
  • $ printf %s $'\u1234\u00FF' | iconv -t utf-16 | xxd -g2 -e
  • 00000000: feff 1234 00ff ..4...
  • ```
  • As you can see, you'll have to contend with the `\uFEFF` BOM if you do this.
  • Note that this will barf if you give it `$'\xFF'`, which isn't valid UTF-8. Mixing the two encodings is a recipe for sadness.
#1: Initial revision by user avatar r~~‭ · 2025-05-31T17:18:41Z (4 days ago)
I don't think you can persuade Bash to use non-UTF-8 characters internally—I expect much of its code assumes that strings are ASCII-compatible. So `$'\u00FF'` will always translate, inside Bash, to the UTF-8 byte sequence `c3 bf`, and that's what

If you want to take a UTF-8 byte sequence that Bash (or another utility) has produced and translate it to UTF-16, use iconv:

```
$ printf %s $'\u1234\u00FF' | iconv -t utf-16 | xxd -g2 -e
00000000: feff 1234 00ff                            ..4...
```

As you can see, you'll have to contend with the `\uFEFF` BOM if you do this.

Note that this will barf if you give it `$'\xFF'`, which isn't valid UTF-8. Mixing the two encodings is a recipe for sadness.