LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   corrupted redirect (https://www.linuxquestions.org/questions/programming-9/corrupted-redirect-834983/)

sharky 09-28-2010 12:13 PM

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?

GrapefruiTgirl 09-28-2010 12:18 PM

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:


sharky 09-28-2010 02:32 PM

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?

GrapefruiTgirl 09-28-2010 02:37 PM

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.

sharky 09-28-2010 02:40 PM

Quote:

Originally Posted by GrapefruiTgirl (Post 4111775)
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=35:pi=5:so=5:bd=5:cd=5:or=31:mi=0:ex=32'
export LS_COLORS
I change the ls alias to "alias ls='ls --color-tty'" and the problem is solved.

sharky 09-28-2010 02:41 PM

Quote:

Originally Posted by sharky (Post 4111777)
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.

GrapefruiTgirl 09-28-2010 02:43 PM

Nice going ;) now you can mark this [SOLVED] if you're satisfied, using the Thread Tools menu near the top.

Cheers!


All times are GMT -5. The time now is 02:49 AM.