为神马把ls结果存文件会看到乱码?

sh/bash/dash/ksh/zsh等Shell脚本
回复
头像
anix
帖子: 88
注册时间: 2009-05-18 22:33
联系:

为神马把ls结果存文件会看到乱码?

#1

帖子 anix » 2011-04-20 15:19

命令:
filelist=`ls |grep "[^/]$"` #列出除去目录的所有文件
echo $filelist
可以显示正常的文件列表,而要对其进行操作时,shell提示:
".........inx及相关新技术的应用实践.ppt\033[0m*\n\033[01;32m高级Bash脚本编程指南.pdf\033[0m*': File name too long"
echo $filelist > /dev/shm/tmp.txt
后打开这个文件发现下面格式的内容:

[[0m^[[01;32m10部算法经典著作的合集.chm^[[0m*
Absolute_OpenBSD.pdf
Advanced.Linux.3D.Graphics.Programming.pdf
^[[01;32mAjax.基础教程.pdf^[[0m*
An_Introduction_to_GCC_中文.pdf
APRESS-Automating_Unix_And_Linux_Administration.chm
APRESS-Tuning_And_Customizing_A_Linux_System.chm
^[[01;32marchlinux.pdf^[[0m*
Asynchronous Events.pdf
Beginning Google Maps Applications With PHP And Ajax - From Novice To Professional (2006).pdf
creating a transparent openbsd firewall.pdf
^[[01;32mcygwin中文教程.pdf^[[0m*
^[[01;32m[C和指针].pdf^[[0m*
^[[01;32m[C陷阱与缺陷].pdf^[[0m*
^[[01;32mEmacs_User's_Guide_中方版.pdf^[[0m*
fvwm实例分析.pdf
^[[01;32mGrub2基础教程.pdf^[[0m*
请问这是怎么回事?
应该肿么办?
谢谢~
上次由 anix 在 2011-04-22 12:18,总共编辑 4 次。
I firmly believe that the Internet and knowledge should be open, public, and accessible to everyone without any restrictions.
头像
anix
帖子: 88
注册时间: 2009-05-18 22:33
联系:

Re: 为神马把ls结果存文件会看到乱码?

#2

帖子 anix » 2011-04-20 19:39

I firmly believe that the Internet and knowledge should be open, public, and accessible to everyone without any restrictions.
sk1418
帖子: 229
注册时间: 2007-07-01 17:36
系统: (En):System
来自: (En):address
联系:

Re: 为神马把ls结果存文件会看到乱码?

#3

帖子 sk1418 » 2011-04-20 20:00

我特意建了两个中文名的文件。 按你的脚本,输出的文件没有所谓的“乱码”, 也是zsh.

另外,为什么
`ls |grep "[^\n]$"`

是 :
#列出除去目录的所有文件

你ls是别名?

我怎么觉得应该是 ls -F |grep "[^/]$" 呢
---
regards,

Kent
头像
adam8157
帖子: 2794
注册时间: 2009-03-05 16:31
联系:

Re: 为神马把ls结果存文件会看到乱码?

#4

帖子 adam8157 » 2011-04-20 20:24

那些都是颜色...
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

Re: 为神马把ls结果存文件会看到乱码?

#6

帖子 eexpress » 2011-04-20 23:05

● type ls
ls 已被别名为“ls --color=auto”

别带颜色。
● 鸣学
头像
anix
帖子: 88
注册时间: 2009-05-18 22:33
联系:

Re: 为神马把ls结果存文件会看到乱码?

#7

帖子 anix » 2011-04-22 12:02

原来是别名的问题啊 :em05 ,,谢谢各位啦~~ :em05
I firmly believe that the Internet and knowledge should be open, public, and accessible to everyone without any restrictions.
头像
anix
帖子: 88
注册时间: 2009-05-18 22:33
联系:

Re: 为神马把ls结果存文件会看到乱码?

#8

帖子 anix » 2011-04-22 12:17

您说得对,是grep "[^/]$",已纠正
sk1418 写了:我特意建了两个中文名的文件。 按你的脚本,输出的文件没有所谓的“乱码”, 也是zsh.
另外,为什么
`ls |grep "[^\n]$"`

是 :
#列出除去目录的所有文件

你ls是别名?

我怎么觉得应该是 ls -F |grep "[^/]$" 呢
I firmly believe that the Internet and knowledge should be open, public, and accessible to everyone without any restrictions.
回复