Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:


source ~/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
    case "$1" in
        *.gz)   DECOMPRESSOR="gunzip -c" ;;
        *.bz2)  DECOMPRESSOR="bunzip2 -c" ;;
        *)  DECOMPRESSOR="cat" ;;
    if $DECOMPRESSOR -- "$1" | file - | grep -q troff; then
        if echo "$1" | grep -q ^/; then #absolute path
            man -- "$1" | cat -s
            man -- "./$1" | cat -s
        $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" ;;
   if [ -x "`which identify`" ]; then
     identify "$1"
     echo "No identify available"
     echo "Install ImageMagick to browse images"
   fi ;;
    case "$1" in
        *.gz)   DECOMPRESSOR="gunzip -c" ;;
        *.bz2)  DECOMPRESSOR="bunzip2 -c" ;;
    if [ ! -z $DECOMPRESSOR ] ; then
        $DECOMPRESSOR -- "$1" ;

if [ -d "$1" ] ; then
    /bin/ls -alF -- "$1"
    lesspipe "$1" 2> /dev/null
share|improve this question
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
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
up vote 1 down vote accepted

I think your problem is addressed on this FAQ page for the less command (see section "Why are there problems if my .cshrc, .profile or ENV files produce output?"):

If you use the LESSOPEN feature, having your shell produce output can cause other problems. Since less uses the shell to invoke the LESSOPEN filter, the output from the shell will appear at the beginning of the output from the filter program, causing it to appear to be part of the file.

share|improve this answer
Welcome to *nix.SE. Please paste the most relevant/important information from links in-line (e.g., in a quote block), to avoid link-rot. – HalosGhost Oct 2 '14 at 17:25
I have to accept this awnser unchecked since I no longer work on the relevant system or have access to it. I took the freedom to quote the link. Cheers – ted Oct 8 '14 at 17:59

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.