Why is GNU `less` just showing the output of my title script instead of the file contents?

1

1

I'm using csh as my terminal and I have a script that runs when I change directories that replaces the window title with the current directory. I have it run initially in my .cshrc file as well so that it will change the window title in a new shell.

When I use less to view a text file within the console, instead of the file contents, I will see the output of this script. This effectively renders less useless.

Ben Richards

Posted 2014-03-19T14:09:27.730

Reputation: 11 662

Answers

1

Your problem is caused by having the ~/.cshrc file output things to the console which interfere with the operation of less.

One way to solve this is to check for interactive shells before doing anything that affects the console or changes the way that shell scripts would run (e.g., setting aliases for cd).

if ($?prompt) then
    # Do things that affect interactive shells here
endif

Kevin Panko

Posted 2014-03-19T14:09:27.730

Reputation: 6 339

1

According to this FAQ for Less on the developer homepage, it turns out that having anything that generates output to the console (which my window title script does) in the .cshrc file can interfere with the output of less. Apparently less invokes the shell to open and view files, and since any new instance of the shell will automatically execute the commands in .cshrc, whatever console output that occurs at that step will interfere with the tool's operation.

The solution is to remove the invocation of my script from the .cshrc file. I can put it into the .login file, but there is the caveat that any new invocation of the shell will not re-execute the commands in that file.

Ben Richards

Posted 2014-03-19T14:09:27.730

Reputation: 11 662