Re: 'ls' name and 'ls | grep name' different

From: Kyle Evans <kevans_at_FreeBSD.org>
Date: Sat, 09 Mar 2024 16:40:35 UTC
On 3/9/24 10:37, Michael Sierchio wrote:
> 
> 
> On Sat, Mar 9, 2024 at 11:19 AM φ Dhénin Jean-Jacques <dhenin@gmail.com 
> <mailto:dhenin@gmail.com>> wrote:
> 
>     Bonjour,
> 
>     I explain  it as simple as possible:
> 
>     :;  set | egrep 'LC_A|LANG'
>     GDM_LANG=fr_FR.UTF-8
>     LANG=fr_FR.UTF-8
>     LC_ALL=fr_FR.UTF-8
>     SLIM_LANG=fr_FR.UTF-8
> 
>     :;  ls -i  1989* ; ls -i | grep 1989 ;  ls -ib  1989* ; ls -ib |
>     grep 1989
>     9920 1989 Amn*??*sia.mp4
>       9920 1989 Amn*é*sia.mp4
>     9920 1989 Amn\303\251sia.mp4
>       9920 1989 Amn\303\251sia.mp4
> 
> 
> Bonjour J-J –
> 
> It's not that the pipe modifies the stream, it's that 'ls' has decided 
> that 'e-accent-aigu' is unprintable in the current locale.
> 
> Try ls -B and then investigate the locale.
> 
> *-B*       Force  printing	of  non-printable  characters  (as  defined by
> 	/ctype/(3)  <https://man.freebsd.org/cgi/man.cgi?query=ctype&sektion=3&apropos=0&manpath=FreeBSD+14.0-RELEASE+and+Ports>	and current locale settings) in	file  names  as	*\*/xxx/,
> 	       where/xxx/  is the	numeric	value of the character in octal.  This
> 	       option is not defined in	IEEE Std 1003.1-2008 ("POSIX.1")
> 

ls(1) notably does toggle this behavior on by default only if stdout is 
a tty requiring the above noted flag, and leaves it disabled if it's piping:

https://cgit.freebsd.org/src/tree/bin/ls/ls.c#n241

This gives grep the chance to just let it render.

Thanks,

Kyle Evans