Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get accented letters to actually work on bash?

My bash installation on cygwin doesn't handle accented letters properly. I tried adding

set input-meta on    # to accept 8-bit characters set output-meta on   # to show 8-bit characters set convert-meta on  # to show it as character, not the octal representation 

to my input rc, but this doesn't quite work yet. Indeed, if I type

$ echo ù 

then before i press enter it is automatically changed to

$ echo \303 

although the output is right, for I get

$ echo \303 ù 

I get the same result for anyother accented letter. Usually though I use a non-italian keyboard, and I use autohotkey to substitute letters with an apostrophe after them with an accented letter. When this is the case, accented letters get substituted with a \302, and they print garbage depending on the letter: prints a 3y for a ù, a ¢ for an ò, and nothing for everething else.

How do I get all this to make sense?

EDIT: my locale settings, cygwin version and terminal are the following

$ uname -a CYGWIN_NT-6.1-WOW64 ferdi-Asus 1.7.17(0.262/5/3) 2012-10-19 14:39 i686 Cygwin $ locale LANG=it_IT.UTF-8 LC_CTYPE="it_IT.UTF-8" LC_NUMERIC="en_US.UTF-8" LC_TIME="it_IT.UTF-8" LC_COLLATE="it_IT.UTF-8" LC_MONETARY="it_IT.UTF-8" LC_MESSAGES="it_IT.UTF-8" LC_ALL= $ tty /dev/pty1 

I'm invoking it simply clicking the Cygwin terminal link. It redirects to

C:\cygwin\bin\mintty.exe -i /Cygwin-Terminal.ico - 

The relevant part of the autohotkey script is the following

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases. SendMode Input  ; Recommended for new scripts due to its superior speed and reliability. SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory. ... ::avra'::avrà ::avro'::avrò ... 
like image 964
Ferdinando Randisi Avatar asked Oct 26 '12 20:10

Ferdinando Randisi


People also ask

How does bash handle special characters?

Bash Character Escaping. Except within single quotes, characters with special meanings in Bash have to be escaped to preserve their literal values. In practice, this is mainly done with the escape character \ <backslash>.

How do you escape special characters in bash?

3.1. 2.1 Escape CharacterA non-quoted backslash ' \ ' is the Bash escape character. It preserves the literal value of the next character that follows, with the exception of newline .


1 Answers

To get accented letters on bash via Cygwin using Mintty 1.1.2 just do the following:

  1. Go to the menu (if you don't see any menu, right click on your Terminal).
  2. Click Options....
  3. Click Text.
  4. Change the Locale to C.
  5. Change the Character set to ISO-8859-1 (Western European).

Changing Locale and Character set in Mintty 1.1.2

Then test it:

Echoing accented letters in Mintty 1.1.2

like image 122
Rubens Mariuzzo Avatar answered Sep 21 '22 10:09

Rubens Mariuzzo