Bash – Non-ascii in Cygwin bash command line causes error

bashcygwin;

I'm calling bash from cmd.exe like this

c:\cygwin\bin\bash --login -c "echo ф"

and get on Cygwin 2.8.0

/usr/bin/bash: echo ф: command not found

It treats the parameter as part of the command name. Doing the same on Cygwin 2.5.2 I get the output ф.

Best Answer

Since this used to work, and works fine for people running bash on Unices (I tested on Debian here), I think you've found a Cygwin bug. The Cygwin project has a page about reporting Cygwin bugs. They have a bunch of useful information and steps there, far too long to summarize here.

In the meantime, I suspect you can work around this by escaping the character. Bash's echo, when given the -e flag, interprets various escape sequences:

c:\cygwin\bin\bash --login -c "echo -e '\xd1\x84'"

should work. Hexadecimal D1 84 is the UTF-8 encoding of ф. If you have the unicode tool, it'll tell you—but so will just echoing the character to od or xxd:

$ echo -n 'ф' | od -t x1
0000000 d1 84
0000002

$ echo -n 'ф' | xxd -p
d184

The Cygwin FAQ tells me it uses UTF-8 by default, so that should work. But of course you can use other encodings too (I think Windows mostly uses UTF16le):

$ echo -n 'ф' | iconv -t utf16le | xxd -p
4404
Related Question