LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-28-2010, 12:13 PM   #1
sharky
Member
 
Registered: Oct 2002
Posts: 569

Rep: Reputation: 84
corrupted redirect


I do a long listing on a directory, pipe it to awk '{print $11}' and I see something similar to this;

Quote:
/acrobat/8.1.2
/firefox/3.0.8
/cadappl_sde/java/1.6.0_06
/kdiff3/0.9.92
/matlab/R2009b_SP1
/openoffice/3.1.0/
/qt/4.5.2
/vim/7.1.0
If I redirect it to a file and then 'cat' the file I see the same thing. However, if I open it in vim I see this;

Quote:
^[[34m/acrobat/8.1.2^[[0m
^[[34m/firefox/3.0.8^[[0m
^[[34m/cadappl_sde/java/1.6.0_06^[[0m
^[[34m/kdiff3/0.9.92^[[0m
^[[34m/matlab/R2009b_SP1^[[0m
^[[34m/openoffice/3.1.0/^[[0m
^[[34m/qt/4.5.2^[[0m
^[[34m/vim/7.1.0^[[0m
If I open the file in nedit I see this;

Quote:
<esc>[34m/acrobat/8.1.2<esc>[0m
<esc>[34m/firefox/3.0.8<esc>[0m
<esc>[34m/cadappl_sde/java/1.6.0_06<esc>[0m
<esc>[34m/kdiff3/0.9.92<esc>[0m
<esc>[34m/matlab/R2009b_SP1<esc>[0m
<esc>[34m/openoffice/3.1.0/<esc>[0m
<esc>[34m/qt/4.5.2<esc>[0m
<esc>[34m/vim/7.1.0<esc>[0m
Any ideas where those escape sequences are originating and why they show up only in the editor?
 
Old 09-28-2010, 12:18 PM   #2
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556
If using `ls` to do the listing, try:
Code:
ls --color=never
OR
Code:
/bin/ls
instead..

The garbage you see are color escape codes, for colorizing the output in your terminal. This is often set up by making `ls` an alias to `ls --color=something`, in either /etc/profile or ~/.profile or ~/.bash_profile or one of the other similar profile files.
Here's an example from my machine, where my `ls` command is aliased:
Code:
sasha@reactor: alias
alias Eterm='/home/sasha/.wrapper-scripts/eterm-wrapper.sh'
alias d='dir'
alias dir='/bin/ls $LS_OPTIONS --format=vertical'
alias eterm='/home/sasha/.wrapper-scripts/eterm-wrapper.sh'
alias ls='/bin/ls $LS_OPTIONS'
alias mc='. /usr/share/mc/bin/mc-wrapper.sh'
alias mv='mv -bv'
alias nano='nano -m'
alias rxvt='/home/sasha/.wrapper-scripts/rxvt-wrapper.sh'
alias spkg='/usr/bin/src2pkg -Q -A -C -VV -W -R -a=x86_64 -p=/usr -f="-O2 -fPIC -Wall -mtune=native -march=native -pipe -fomit-frame-pointer"'
alias spkh='/usr/bin/src2pkg --help'
alias v='vdir'
alias vdir='/bin/ls $LS_OPTIONS --format=long'
alias xterm='/home/sasha/.wrapper-scripts/xterm-wrapper.sh'
sasha@reactor: echo $LS_OPTIONS
-F -b -T 0 --color=auto
sasha@reactor:
 
Old 09-28-2010, 02:32 PM   #3
sharky
Member
 
Registered: Oct 2002
Posts: 569

Original Poster
Rep: Reputation: 84
GrapefruiTgirl, I think you're on to something. If I unalias ls prior to generating the file then the escape sequences are not there.

Should this be classified as a bug in ls?
 
Old 09-28-2010, 02:37 PM   #4
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556
No, it's not a bug. It's a feature! It's an option of `ls` that's being put to use, probably set up by you (perhaps unknowingly) or your OS by default, or by your sysadmin if that's not you. Your OS wants you to have colored ls.

Read the `ls` man page, and the `bash` man page to read about aliases (or whatever shell you use, if not bash).

Comment out the entry in the .profile or /etc/profile or whatever file it is, where the alias is set, if you prefer not to have it turned on.
 
Old 09-28-2010, 02:40 PM   #5
sharky
Member
 
Registered: Oct 2002
Posts: 569

Original Poster
Rep: Reputation: 84
Quote:
Originally Posted by GrapefruiTgirl View Post
No, it's not a bug. It's a feature! It's an option of `ls` that's being put to use, probably set up by you (perhaps unknowingly) or your OS by default, or by your sysadmin if that's not you. Your OS wants you to have colored ls.

Read the `ls` man page, and the `bash` man page to read about aliases (or whatever shell you use, if not bash).

Comment out the entry in the .profile or /etc/profile or whatever file it is, where the alias is set, if you prefer not to have it turned on.
You're absolutely right. I set this manually in my .bashrc.user

Quote:
# set colors for ls
alias ls='ls --color'
LS_COLORS='di=34:fi=0:ln=35i=5:so=5:bd=5:cd=5r=31:mi=0:ex=32'
export LS_COLORS
I change the ls alias to "alias ls='ls --color-tty'" and the problem is solved.
 
Old 09-28-2010, 02:41 PM   #6
sharky
Member
 
Registered: Oct 2002
Posts: 569

Original Poster
Rep: Reputation: 84
Quote:
Originally Posted by sharky View Post
You're absolutely right. I set this manually in my .bashrc.user



I change the ls alias to "alias ls='ls --color-tty'" and the problem is solved.
oop. That's =tty, not -tty.
 
Old 09-28-2010, 02:43 PM   #7
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556
Nice going now you can mark this [SOLVED] if you're satisfied, using the Thread Tools menu near the top.

Cheers!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
my os is corrupted chandra kant Linux - Newbie 8 08-14-2010 01:12 PM
Ubuntu 9.x install corrupted NTFS partition; repair corrupted TrueCrypt partition halfer Linux - General 1 06-30-2009 02:59 PM
how would I tell if anything is corrupted? newbiesforever MEPIS 8 11-05-2008 10:12 PM
Corrupted SFTP gizza23 Linux - Software 8 08-04-2005 11:29 PM
corrupted fs, please help class_struggle Linux - Newbie 8 08-21-2004 06:22 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:06 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration