6

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.

1

3 Answers 3

4

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

Sign up to request clarification or add additional context in comments.

2 Comments

Could you explain how it checks whether stdin is associated with files? I thinks this is the part I wanna know. Thank you.
We C/Unix old-timers remember the rookie mistake of doing a printf between getting an error and trying to turn the errno into a message, because printf would do a call to determine whether it should do line buffering or not, so all your errno would tell you is "ENOTTY" (Not a TTY).
0

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.

Comments

-1
$ 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

1 Comment

No that error message was the result of running "less" barely. I didn't make myself clear...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.