为什么文件名用“â”号包围?

Ala*_*Kis 2 shell character-encoding utilities locale

添加alias rm='rm -i'到我的~/.bashrc文件后(因为当我删除文件时,它没有要求确认),文件名用“â”符号包围,如下例所示:

rm: cannot remove âfile1.txtâ: No such file or directory
Run Code Online (Sandbox Code Playgroud)

别名列表:

alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias rm='rm -i'
alias vi='vim'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
Run Code Online (Sandbox Code Playgroud)

注意:我从我的 Windows 机器上使用 PuTTY 连接到我的 CentOS 机器,所以这绝对是一个字符编码问题。在我的 VM 中使用 Ubuntu 来宾,一切都很好。智能报价会根据需要显示。

jll*_*gre 6

这些âs 是 UTF-8 引号,您当前的终端无法正确显示,在 ISO-8859-1 或类似文件中配置。

您可以通过设置匹配的语言环境或 POSIX 来正确显示:

$ rm file.txt
rm: cannot remove â  file.txtâ : No such file or directory
$ LC_ALL=en_US.UTF-8 rm file.txt
rm: cannot remove â  file.txtâ : No such file or directory
$ LC_ALL=C rm file.txt
rm: cannot remove 'file.txt' : No such file or directory
Run Code Online (Sandbox Code Playgroud)
$ rm foo 2>&1 | od -c
0000000   r   m   :       c   a   n   n   o   t       r   e   m   o   v
0000020   e     342 200 230   f   o   o 342 200 231   :       N   o    
0000040   s   u   c   h       f   i   l   e       o   r       d   i   r
0000060   e   c   t   o   r   y  \n
0000067
$ LC_ALL=C rm foo 2>&1 | od -c
0000000   r   m   :       c   a   n   n   o   t       r   e   m   o   v
0000020   e       '   f   o   o   '   :       N   o       s   u   c   h
0000040       f   i   l   e       o   r       d   i   r   e   c   t   o
0000060   r   y  \n
0000063
Run Code Online (Sandbox Code Playgroud)