Go Back   The macosxhints Forums > OS X Help Requests > UNIX - Newcomers



Reply
 
Thread Tools Rating: Thread Rating: 4 votes, 5.00 average. Display Modes
Old 11-02-2003, 08:15 PM   #1
Iie-Kyo
Prospect
 
Join Date: Oct 2003
Posts: 18
The dir/ls command, more command, and color

Well, with the release of Panther, it ended up nuking a lot of my custom-done UNIX modifications in the /etc directory.

One of the more annoying replacements it did was to nuke the little alias I made for the dir command:
dir -Al --color=always | more

So when I went back into the Terminal to fix it up and add this to my list of aliases, I end up getting stuff like this:
drwx------ 44 skywalk staff 1496 Nov 2 15:08 ESC[01;34mLibraryESC[0m
drwxr-xr-x 18 skywalk staff 612 Sep 14 12:29 ESC[01;34mMP3sESC[0m
drwx------ 2 skywalk staff 68 Jun 4 2002 ESC[01;34mMoviesESC[0m
drwx------ 4 skywalk staff 136 Aug 30 14:56 ESC[01;34mMusicESC[0m
drwx------ 5 skywalk staff 170 Sep 1 00:26 ESC[01;34mPicturesESC[0m

However, if I don't pipe it through more, the colors end up coming out fine.

What's wrong with more? It accepted color inputs in 10.2, why can't it do that now?

As a sidenote, I *am* using the Fink GNU-Based version of fileutils (4.1)... if that says anything. And the 10.2 more *did* properly accept the GNU version of dir.
__________________
"The light at the end of the tunnel is the headlamp to an oncoming train."
Iie-Kyo is offline   Reply With Quote
Old 11-03-2003, 12:17 AM   #2
blb
All Star
 
Join Date: Jan 2002
Location: CO, USA
Posts: 908
Have you tried piping to less instead of more? less tends to be more capable.
blb is offline   Reply With Quote
Old 11-04-2003, 06:36 AM   #3
pmccann
Major Leaguer
 
Join Date: Jan 2002
Location: Adelaide, South Australia
Posts: 470
I think you'll probably need just a little bit more than a pipe to less: you also need to let less know that the control sequences should be interpreted. Have a go with piping to "less -R", which just worked for me (using a custom display of files: "lc" for any old-timers still left in here).

Oh yeah, "more -R" seems to work fine as well. (Edit: well that ain't too surprising given that "more" is "less". cf the parallel thread in Unix General. Of course the behaviour of each may well depend on which way it's invoked, so that the traditional "moreish" things work etc etc)

Cheers,
Paul

Last edited by pmccann; 11-04-2003 at 06:51 AM.
pmccann is offline   Reply With Quote
Old 11-04-2003, 04:20 PM   #4
jkp23
Triple-A Player
 
Join Date: Feb 2003
Location: back in t'ol' smoke :(
Posts: 225
not for me

Well that didnt seem to work for me. I still get non-colored output. any ideas?

I am running the panther retail build, and I ran 'more -V' which gave me...

Code:
more -V
less 378
Copyright (C) 2002 Mark Nudelman

less comes with NO WARRANTY, to the extent permitted by law.
For information about the terms of redistribution,
see the file named README in the less distribution.
Homepage: http://www.greenwoodsoftware.com/less
also so just to note - my standard 'lc' command is alaised to 'ls -laG | more ...'
__________________
JKP.
jkp23 is offline   Reply With Quote
Old 11-04-2003, 04:36 PM   #5
mervTormel
League Commissioner
 
Join Date: Jan 2002
Posts: 5,536
$ which ls

/sw/bin/ls

or

/bin/ls

what does

/bin/ls -Gl | less -R

get you?
mervTormel is offline   Reply With Quote
Old 11-04-2003, 04:41 PM   #6
jkp23
Triple-A Player
 
Join Date: Feb 2003
Location: back in t'ol' smoke :(
Posts: 225
Sorted.

its OK merv.

I've just read the ls manual, and discovered that you can set a couple of environment variables that sorts it out.

just add this to your .bashrc

Code:
# correct the problem with ls and more
export CLICOLOR=true
export CLICOLOR_FORCE=true
that forces a coloured output to things other than a terminal (ie - less). you dont need to use any switches on more (less).

solved.
__________________
JKP.
jkp23 is offline   Reply With Quote
Old 11-09-2003, 05:24 PM   #7
jkp23
Triple-A Player
 
Join Date: Feb 2003
Location: back in t'ol' smoke :(
Posts: 225
./configure is broken now...!

An interesting oddity has happened since I solved the problem using these environ variables:

If I try to run configure for some peice of software to generate a makefile, get the following output:

Code:
checking whether build environment is sane... configure: error: ls -t 
appears to fail.  Make sure there is not a broken
alias in your environment
configure: error: newly created file is older than distributed files!
Check your system clock
Now from some investigation I know it is nothing to do with the system clock, but i does infact relate to the output of ls. All configure scripts by default try some kind of test using ls, that setting these environ variables breaks.

Is there another way I can solve the problem, or alternatively I thought one way around it would be to write a shell script that takes a command as an input , and would disable the envrions (set them to null), run the passed command, and then renable the variables? bit of a botch I know, but I cant see another way....

/edit: fold -mt
__________________
JKP.

Last edited by mervTormel; 11-09-2003 at 05:44 PM.
jkp23 is offline   Reply With Quote
Old 11-09-2003, 05:56 PM   #8
mervTormel
League Commissioner
 
Join Date: Jan 2002
Posts: 5,536
ok here. investigate some more. and why conceal "some piece of software" from us? tell us what and let's compare realities.

Code:
$ set | grep COLOR 
CLICOLOR=1
CLICOLOR_FORCE=1
LSCOLORS=exfxcxdxbxegedabagacad

darkstat-2.6 $ ./configure 
checking for a BSD-compatible install... /sw/bin/install -c
checking whether build environment is sane... yes
...
mervTormel is offline   Reply With Quote
Old 11-09-2003, 06:02 PM   #9
jkp23
Triple-A Player
 
Join Date: Feb 2003
Location: back in t'ol' smoke :(
Posts: 225
merv - its not 'some piece'...its every piece!

at least in the last few days, and disabling them always fixed it. odd.

oh and:

Code:
set | grep COLOR 
CLICOLOR=true
CLICOLOR_FORCE=true
__________________
JKP.
jkp23 is offline   Reply With Quote
Old 11-09-2003, 06:21 PM   #10
mervTormel
League Commissioner
 
Join Date: Jan 2002
Posts: 5,536
ah.

well, do you alias ls?

$ alias ls
-bash: alias: ls: not found

and the time error is cumulative from the sane/ls error, so solve the ls error and time issue should go away.

from configure...
Code:
echo "$as_me:$LINENO: checking whether build environment is sane" >&5
echo $ECHO_N "checking whether build environment is sane... $ECHO_C" 
>&6
# Just in case
sleep 1
echo timestamp > conftest.file
# Do `set' in a subshell so we don't clobber the current shell's
# arguments.  Must try -L first in case configure is actually a
# symlink; some systems play weird games with the mod time of symlinks
# (eg FreeBSD returns the mod time of the symlink's containing
# directory).
if (
   set X `ls -Lt $srcdir/configure conftest.file 2> /dev/null`
   if test "$*" = "X"; then
      # -L didn't work.
      set X `ls -t $srcdir/configure conftest.file`
   fi
   rm -f conftest.file
   if test "$*" != "X $srcdir/configure conftest.file" \
      && test "$*" != "X conftest.file $srcdir/configure"; then

      # If neither matched, then we have a broken ls.  This can happen
      # if, for instance, CONFIG_SHELL is bash and it inherits a
      # broken ls alias from the environment.  This has actually
      # happened.  Such a system could not be considered "sane".
      { { echo "$as_me:$LINENO: error: ls -t appears to fail.  Make 
sure there is not a broken
alias in your environment" >&5
echo "$as_me: error: ls -t appears to fail.  Make sure there is not a 
broken
alias in your environment" >&2;}
   { (exit 1); exit 1; }; }
   fi

   test "$2" = conftest.file
   )
then
   # Ok.
   :
else
   { { echo "$as_me:$LINENO: error: newly created file is older than 
distributed files!
Check your system clock" >&5
echo "$as_me: error: newly created file is older than distributed 
files!
Check your system clock" >&2;}
   { (exit 1); exit 1; }; }
fi
mervTormel is offline   Reply With Quote
Old 11-09-2003, 06:31 PM   #11
jkp23
Triple-A Player
 
Join Date: Feb 2003
Location: back in t'ol' smoke :(
Posts: 225
id got that far merv...i know its ls as i had a look at the configure code!

the other answer is i dont alias ls...just add the environ variables.

/me = puzzled!
__________________
JKP.
jkp23 is offline   Reply With Quote
Old 11-09-2003, 06:47 PM   #12
mervTormel
League Commissioner
 
Join Date: Jan 2002
Posts: 5,536
well, step thru the tests...
Code:
cd /path/to/configure

touch conftest.file
srcdir=.

ls -Lt $srcdir/configure conftest.file

ls -t $srcdir/configure conftest.file

set X `ls -t $srcdir/configure conftest.file`

echo "$*"
what are the results? gotta play a bit of a detective to ferret this one out.

oh, what is your term type?

echo $TERM
mervTormel is offline   Reply With Quote
Old 11-09-2003, 08:41 PM   #13
jkp23
Triple-A Player
 
Join Date: Feb 2003
Location: back in t'ol' smoke :(
Posts: 225
So ...

Code:
ls -Lt $srcdir/configure conftest.file
conftest.file ./configure
ls -t $srcdir/configure conftest.file
conftest.file ./configure
set X `ls -t $srcdir/configure conftest.file`
echo "$*"
X conftest.file ./configure
But im lost now!....
__________________
JKP.
jkp23 is offline   Reply With Quote
Old 11-09-2003, 10:26 PM   #14
stetner
MVP
 
Join Date: Jan 2002
Location: Brisbane, Australia
Posts: 1,108
What you need t do is to set your env vars for an interactive shell, but unset them for a non interactive shell, that way configure will get 'normal' ls output it wants and you will have pretty colors 8-)

Quick hacked up example....
Code:
$ export FOO=BAR

$ echo $FOO
BAR
$ cat xx
#! /bin/bash
echo $- "<-----"
X=`echo $- | grep i`
if [ "X$X" == "X" ]
then
        echo no inter $X
        unset FOO
else
        echo interactive $X
        export FOO=BAR
fi
echo "XXX $FOO XXX"

$ ./xx
hB <-----
no inter
XXX  XXX

$ . ./xx
himBH <-----
interactive himBH
XXX BAR XXX
The 'i' in $- indicates an interactive shell and I can unset the FOO variable in non-interactive shells.
__________________
Douglas G. Stetner
UNIX Live Free Or Die
stetner is offline   Reply With Quote
Old 11-10-2003, 06:11 AM   #15
jkp23
Triple-A Player
 
Join Date: Feb 2003
Location: back in t'ol' smoke :(
Posts: 225
Well cheers Stener...

That was kinda like what I was thinking, but It still doesnt explain why merv can use exactly the same variables as me and not have a problem!

worst comes to the worse and ill do that.

Many thanks
__________________
JKP.
jkp23 is offline   Reply With Quote
Old 11-14-2003, 07:13 PM   #16
Iie-Kyo
Prospect
 
Join Date: Oct 2003
Posts: 18
Re: Sorted.

Quote:
Originally posted by jkp23
its OK merv.

I've just read the ls manual, and discovered that you can set a couple of environment variables that sorts it out.

just add this to your .bashrc

Code:
# correct the problem with ls and more
export CLICOLOR=true
export CLICOLOR_FORCE=true
that forces a coloured output to things other than a terminal (ie - less). you dont need to use any switches on more (less).

solved.

I've tried shoving this in my /etc/bashrc file but I still get the same garbage as the stuff in the first post.

The environmental variables are set when I do a set, but it doesn't seem to affect anything.

I'll just stick with using the -R switch for now, but if anyone has a reason why as to setting these variables isn't doing anything then I'd like to know.

Thanks a lot!
__________________
"The light at the end of the tunnel is the headlamp to an oncoming train."
Iie-Kyo is offline   Reply With Quote
Old 11-14-2003, 08:17 PM   #17
mervTormel
League Commissioner
 
Join Date: Jan 2002
Posts: 5,536
Re: Re: Sorted.

Quote:
Originally posted by Iie-Kyo
I've tried shoving this in my /etc/bashrc file but I still get the same garbage as the stuff in the first post.

The environmental variables are set when I do a set, but it doesn't seem to affect anything.

I'll just stick with using the -R switch for now, but if anyone has a reason why as to setting these variables isn't doing anything then I'd like to know.

Thanks a lot!

try:

$ TERM=vt100 ls -l
mervTormel is offline   Reply With Quote
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 On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 06:10 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.