Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

On my Mac terminal, printing UTF-8 works in general, but the less doesn't work correctly.

So this works correctly:

$  echo -e '\xe2\x82\xac'   
€

but piping it into less gives something like this:

$  echo -e '\xe2\x82\xac' | less  
<E2><82><AC>

How can this be fixed?

For diagnostics:

I'm using Mac OS 10.6.8. less version 418, Terminal 2.1.2 (273.1).

The output of my locale is this:

$ locale
LANG="en_US.UTF-8"
LC_COLLATE="C"
LC_CTYPE="C"
LC_MESSAGES="C"
LC_MONETARY="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_ALL="C"
share|improve this question
add comment

2 Answers

Works for me with

LANG=
LC_COLLATE="en_US.UTF-8"
LC_CTYPE="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_ALL="en_US.UTF-8"
share|improve this answer
    
LC_CTYPE is the important one. However the rules less uses are bizarre: instead of retrieving the encoding from the locale, it looks for the string "utf-8" (or a few other possibilities) in its name.So you’ll need to use LESSCHARSET if you want some other encoding or if your locale name doesn’t match less’s preconceptions. –  Richard Kettlewell Aug 7 '12 at 22:25
add comment

Okay, I found the answer after some googling. Apparently, LESSCHARSET needs to be set like this:

export LESSCHARSET=utf-8

Now less works fine for me.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.