Skip to content

Instantly share code, notes, and snippets.

@gwpl
Created April 16, 2026 22:28
Show Gist options
  • Select an option

  • Save gwpl/ee1cfbcc0500acd2435ae28f2cbd2ab0 to your computer and use it in GitHub Desktop.

Select an option

Save gwpl/ee1cfbcc0500acd2435ae28f2cbd2ab0 to your computer and use it in GitHub Desktop.
Bash backtick (`) and tilde (~) not working — Unicode modifier letters from dead-key keyboard layouts (Termux, Android, US-Intl)

Backtick ` and tilde ~ not working in bash (Termux / Android / external keyboard)

Symptoms

  • ~ in bash does not expand to your home directory (cd ~ fails or goes nowhere useful)
  • Backticks around a command do not execute it — `ls` is treated as literal text
  • Copy-pasting the characters out of your terminal into a Unicode inspector shows they are not ASCII
  • Common setup where this appears: Lenovo (or other) USB keyboard → Android tablet → Termux → mosh/ssh to remote host
  • Also reproducible with US-International or similar "dead-key" layouts on Linux/macOS desktops

Root cause

Your keyboard is emitting Unicode modifier letters, not ASCII:

What you type What is emitted Codepoint What bash needs Codepoint
` ˋ MODIFIER LETTER GRAVE ACCENT U+02CB ` GRAVE ACCENT U+0060
~ ˜ SMALL TILDE U+02DC ~ TILDE U+007E

Bash, POSIX shells, and virtually all CLI tools only recognize the ASCII versions (U+0060 / U+007E). The Unicode modifier letters look nearly identical but are semantically different characters, so the shell treats them as ordinary text.

Why it happens

These keys are configured as dead keys in your active layout (e.g. "US International"). A dead key waits to combine with the next keystroke to form an accented letter (` + a = à). When the next key is space, nothing, or a non-combinable character, some layouts emit the spacing modifier letter (ˋ, ˜) instead of the plain ASCII character — which breaks shell usage.

On Android with an external keyboard, the layout is controlled by Android, not Termux.

Diagnosis

Run one of these in your terminal, press the offending key, and check the output:

showkey -a           # shows codepoint in hex/octal; expect 0x60 for ` and 0x7e for ~
cat                  # type the key + Enter; paste output into a Unicode inspector
printf '%s' '`' | xxd    # should show 60, NOT cb 8b (UTF-8 for U+02CB)
printf '%s' '~' | xxd    # should show 7e, NOT cb 9c (UTF-8 for U+02DC)

If you see cb 8b / cb 9c instead of 60 / 7e, you have this bug.

Fix

Android + external keyboard (Termux, mosh, ssh)

  1. Settings → System → Languages & input → Physical keyboard
  2. Tap your keyboard name (e.g. "Lenovo …")
  3. Set up keyboard layouts → pick English (US)not "English (US), International style"
  4. Test again in Termux.

Linux desktop

# Check current layout
setxkbmap -query | grep -E 'layout|variant'

# Switch to plain US (no dead keys)
setxkbmap -layout us

Or in your DE's keyboard settings, choose a variant without "dead keys" / "intl".

macOS

System Settings → Keyboard → Input Sources → pick U.S. instead of U.S. International — PC or ABC — Extended.

Quick workaround (if you cannot change the layout)

On most dead-key layouts, pressing the dead key twice or followed by space emits the literal ASCII character:

  • Press ` ` → emits a single `
  • Press ` then Space → emits `
  • Same for ~

Verify the fix

cd ~           # should land in $HOME
echo `whoami`  # should print your username

If both work, you're done.

See also

  • Unicode: U+0060 (GRAVE ACCENT), U+007E (TILDE), U+02CB (MODIFIER LETTER GRAVE ACCENT), U+02DC (SMALL TILDE)
  • man xkeyboard-config — dead-key variants on Linux
  • Android's keyboard layout is shared across all apps, including Termux — there is no Termux-side override for physical keyboards
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment