Why is 'more' giving the 'next file' prompt?

Barry Margolin barmar at think.com
Fri May 4 08:29:54 AEST 1990


In article <1990May3.160744.25250 at bath.ac.uk> exspes at bath.ac.uk (P E Smee) writes:
>Ok, folks, here's one which my boss asked for an answer to the other
>day, and I don't see the answer.  The context is (4 different variants
>of) 4.3BSD  (on 4 different platforms).  Make yourself a small text
>file, say 'fred'.  Then try the command line:
>
>   cat fred | csh -c 'cat >tempxxx ; more tempxxx'
>
>Before 'more' puts anything out, it gives the 'Next file (tempxxx):'
>prompt.  Why does it think tempxxx is the second file?  What's the
>first?

'more' is noticing that its standard input isn't a terminal, so it's first
displaying the standard input.  Here's a way to see this more clearly:
create two text files, 'foo' and 'bar', and then do:

	more foo < bar

First it will show you the contents of 'bar', and the second file will be
'foo'.

You can fix your problem by making 'more's standard input a terminal, e.g.

	cat fred | ( cat >tempxxx ; more tempxxx </dev/tty )

>  The purpose of
>piping through 'cat' into a temp file and then giving that to 'more' as
>an arg is that in that case 'more' will allow you to move backwards;
>while if 'more' is processing stdin you can only go frontwards.

Get 'less'.  It allows going backward in any stream.

>  In the
>context of the original, the shell invocation is needed in order to
>allow the (second) 'cat' and the 'more' to be joined with ';' rather
>than being '|'ed together.

You can also use parentheses, as in my example.

--
Barry Margolin, Thinking Machines Corp.

barmar at think.com
{uunet,harvard}!think!barmar



More information about the Comp.unix.wizards mailing list