Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

In our university we have a script to setup the working environment under linux. Since I am lazy I decided to add this process to the shell initialization by adding source /setup/script to .cshrc. However since I have done so, I can't use less anymore. When I run less somefile, the output of said script is displayed by less instead of the contents of somefile.

I managed to work around the issue by using source /setup/script > /dev/null

So the questions:

  1. Is it wrong/is there a better way, then adding source initscript to .cshrc
  2. How can I continue using less (without the output redirect, the script echos some ussage information I find helpfull)?
  3. Why is this happening?

edit: OK since I feel uncomfortable adding the scripts, here is a minimal example that breaks less for me:

.cshrc:

source ~/test

~/test:

echo "test"

If I now do less test I get test instead of echo "test", by the way the output is the same for other files, I checked. The output is within the less environment (pressing q returns me to the console)

update: There is an additional annoying thing: less imaginaryPathToNonexistingFile- works, same output. less has some sort of memory: every time I change the file I open the display of test is one line down on the screen, until it is right over the filename(END)at the bottom of the console

update: I found that there is an environment variable called LESSOPEN set to |/usr/bin/lesspipe.sh %s (thx vonbrand)

#!/bin/sh -
#
# To use this filter with less, define LESSOPEN:
# export LESSOPEN="|/usr/bin/lesspipe.sh %s"

lesspipe() {
  case "$1" in
  *.[1-9n]|*.man|*.[1-9n].bz2|*.man.bz2|*.[1-9].gz|*.[1-9]x.gz|*.[1-9].man.gz)
    case "$1" in
        *.gz)   DECOMPRESSOR="gunzip -c" ;;
        *.bz2)  DECOMPRESSOR="bunzip2 -c" ;;
        *)  DECOMPRESSOR="cat" ;;
    esac
    if $DECOMPRESSOR -- "$1" | file - | grep -q troff; then
        if echo "$1" | grep -q ^/; then #absolute path
            man -- "$1" | cat -s
        else
            man -- "./$1" | cat -s
        fi
    else
        $DECOMPRESSOR -- "$1"
    fi ;;
  *.tar) tar tvvf "$1" ;;
  *.tgz|*.tar.gz|*.tar.[zZ]) tar tzvvf "$1" ;;
  *.tar.bz2|*.tbz2) bzip2 -dc -- "$1" | tar tvvf - ;;
  *.[zZ]|*.gz) gzip -dc -- "$1" ;;
  *.bz2) bzip2 -dc -- "$1" ;;
  *.zip) zipinfo -- "$1" ;;
  *.rpm) rpm -qpivl --changelog -- "$1" ;;
  *.cpi|*.cpio) cpio -itv < "$1" ;;
  *.gif|*.jpeg|*.jpg|*.pcd|*.png|*.tga|*.tiff|*.tif)
   if [ -x "`which identify`" ]; then
     identify "$1"
   else
     echo "No identify available"
     echo "Install ImageMagick to browse images"
   fi ;;
  *)
    case "$1" in
        *.gz)   DECOMPRESSOR="gunzip -c" ;;
        *.bz2)  DECOMPRESSOR="bunzip2 -c" ;;
    esac
    if [ ! -z $DECOMPRESSOR ] ; then
        $DECOMPRESSOR -- "$1" ;
    fi
  esac
}

if [ -d "$1" ] ; then
    /bin/ls -alF -- "$1"
else
    lesspipe "$1" 2> /dev/null
fi
share|improve this question
2  
We can't know unless you show us the contents of the script. –  terdon Mar 31 '13 at 14:24
    
I can't imagine how they manage to do that, I'd be very interested ;-) –  vonbrand Mar 31 '13 at 14:44
    
@terdon: I added a min example, it is running under Redhat if that helps –  ted Mar 31 '13 at 14:51
    
@vonbrand: From the fact, that the pros here think that it is actually related to script, and what I have found, I am afraid I have to disappoint you: either I have an old/broken/... version of less, or there is some bigger thing besides less doing the breaking –  ted Mar 31 '13 at 14:52
1  
I can't see anything that might have such a bizarre efect there. Anything in ~/.lessrc, any alias for less, setting any variable named LESS<something> somewhere? –  vonbrand Mar 31 '13 at 15:00
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.