share
Unix & Linuxtermux grep fails to detect chinese character
[0] [0] kGdmioT
[2020-04-15 05:13:03]
[ grep android busybox ]
[ https://unix.stackexchange.com/questions/580139/termux-grep-fails-to-detect-chinese-character ]

Given the following file on an Android phone with a Termux installation:

$ cat file.txt
line1
line2
line3
美元

grep 美元 file.txt returns nothing, while grep line file.txt works as expected. Quoting the Chinese characters doesn't seem to have an effect.

On my Arch Linux system, by comparison, these commands all work as expected.

For reference, in Termux, here are the relevant software versions:

GNU bash, version 5.0.16(1)-release (aarch64-unknown-linux-android)
grep (GNU grep) 3.4

And on my Arch Linux laptop:

GNU bash, version 5.0.16(1)-release (x86_64-pc-linux-gnu)
grep (GNU grep) 3.4

I looked on Android Stack Exchange for answers, but didn't find anything.

I tried busybox grep 美元 file.txt, and this worked as expected. My question is, why doesn't just grep ... work?

Edit:

The output of ldd on my phone:

~ $ ldd $(which grep)
libandroid-support.so
libpcre.so
libc.so

~ $ ldd $(which busybox)
libm.so
libc.so
I don't know what does that "Termux" include, but would LC_ALL=en_US.UTF-8 grep 美元 file.txt work? If yes, how about LC_ALL=en_US.UTF-8 grep .元 file.txt? - user313992
The version of bash doesn't matter in this case, more interesting is what libraries is GNU grep linked against. - user313992
@mosvy I tried both of the commands you suggested, and neither of them worked. As for the libraries, is there some way I could check that? Thanks for your comments. - kGdmioT
Try ldd grep. Or if there's no ldd, try LD_TRACE_LOADED_OBJECTS=1 grep . /dev/null. And if even that doesn't work, try LD_DEBUG=1 grep & logcat | grep linker.*linking. If you get something, edit it into the Q. - user313992
@mosvy thanks for your help, and sorry for the 14-month delay... I've edited the question to include the output you asked for. ldd grep returned "file not found" so I used which instead. - kGdmioT