You are not logged in.

#1 2007-10-23 23:19:10

fianella
Member
Registered: 2007-10-15
Posts: 8

[SOLVED] Why are control characters visible in text files??

Hi,

If I direct the output of 'ls' to a file like:

ls > file.txt

and open the file in a editor such as vi, joe or mousepad, it looks like this:

[[01;34m22x22[[0m
[[01;34m24x24[[0m
[[01;34m32x32[[0m
[[0mindex.theme[[0m
[[01;34mscalable[[0m
[[m

I just did the same thing on an old slackware box and no control characters are visible. The same for a recent LFS build. I realize I could probably pipe through dos2unix, but it shouldn't be happening anyway. Any input is appreciated.


Thanks

-Frank

Last edited by fianella (2007-10-24 10:37:00)

Offline

#2 2007-10-23 23:32:03

WyoPBS
Member
From: Cheyenne, WY
Registered: 2007-10-05
Posts: 101
Website

Re: [SOLVED] Why are control characters visible in text files??

at the DOS prompt (sorry, old habits die hard :-) ) type
alias ls
and see what the results are.  Compare that against your slackware or lfs builds.  You will probably find that the color= option is different - most builds will not include the color ANSI sequences if you pipe the output, but if it says color=always the color codes will be included in the redirected file.

Assuming you find an alias for ls that forces color output, you need to find where that is taking place... in your ~/.bashrc file?  in /etc/profile.d?  And change that to alias ls='ls --color=tty' or something sensible like that.


Peter B. Steiger
Cheyenne, WY

Offline

#3 2007-10-24 10:45:01

fianella
Member
Registered: 2007-10-15
Posts: 8

Re: [SOLVED] Why are control characters visible in text files??

Actually, the output of 'alias ls' is the same on both the Arch & Slack boxes:

'ls --color=yes'

I unaliased ls and reset it to  alias ls='ls --color=tty' as you had suggested and the problem disappeared.

Many thanks for your help!

-Frank

Offline

#4 2007-10-24 16:42:37

Gilneas
Member
From: Netherlands
Registered: 2006-10-22
Posts: 320

Re: [SOLVED] Why are control characters visible in text files??

Try out an "\ls" as well. It's the same as a /bin/ls, i.e. ignoring all aliases.

Offline

Board footer

Powered by FluxBB