Question

I'm just wondering about this problem: if I can use something like "ls -al | less", less should have the ability of waiting for input from stdin. What I expected to happen is after running "less" command, the program hang up and wait for input(as a consequence of calling gets() or something like that.)

But why in fact it showed an error message "Missing filename ("less --help" for help)" end exited?

Thank you.

Was it helpful?

Solution

less command can check both argc>1 and stdin be associated with a file(not a tty).

OTHER TIPS

The less command is not designed in that matter. When you execute a command in bash it will display all of the information at once. The less command is used to display the STDOUT of a command or the contents of a file one screen at a time.

$ ls -al | less
total 16
drwxrwxr-x  4 hdante hdante 4096 Nov 24 17:11 .
drwxr-xr-x 88 hdante hdante 4096 Mar 24 22:14 ..
drwxrwxr-x  2 hdante hdante 4096 Nov 25 01:55 new
drwxrwxr-x  3 hdante hdante 4096 Nov 24 18:27 old
(END)

It works. Something is wrong with your less. From less manual pages:

http://www.linuxmanpages.com/man1/less.1.php https://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man1/less.1.html

The manual describes the filename as optional.

Hints to diagnose your problem:

  • try alias | grep less, to see if the command is being modified
  • try set | grep LESS, and check the scripts being run by LESSCLOSE and LESSOPEN
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top