Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: how to either ignore or deal with Icon$'\r' files on macOS



On Thu, Jun 20, 2019 at 5:06 PM TJ Luoma <luomat@xxxxxxxxx> wrote:
>
> Icon$'\r'

So, $'\r' is zsh's representation of a carriage return character.
It's very strange that anything would deliberately be using
carriage-return in a file name, but ...

> for i in *
> do
>     if [ "$i" != "Icon$'\r'" ]
>     then
>         echo "$i"
>     fi
> done

$'\r' is already a form of quoting,  just *don't* put it in double-quotes:

for i in *
do
    if [[ "$i" != Icon$'\r' ]]
    then
        # whatever
    fi
done

You should know better by now than to expect echo to faithfully
reproduce things on its output, it does way too much interpretation of
the argument strings.  In this case, however, the trailing
carriage-return is already "invisible" and echo isn't going to do
anything to make it appear.



Messages sorted by: Reverse Date, Date, Thread, Author