[comp.unix.questions] $<

Dave Lawrence (11/10/88)

Okay, here's a segment of code that doesn't do exactly what everyone things
it should.  It's for an csh-script.

set page = $<
echo $page $#page                /* just for debugging
if ( $page == 'q' ) exit
man $page | less

If I give it 'plot' (no quotes, though), it does:
plot 1
[ plot manpage ]

If I give it 'q', it does:
q 1
[ clean exit ]

If I give it '5 plot', it does:
5 plot 1
if: expression syntax
child of tty exited with return code 1

If I take out the if statement, it still looks up the manpage for plot
as advertised, doesn't find one for q, as expected, and does:
5 plot 1
No manual page for 5 plot

Note that the last results are also gained by man $< | less and an
input of '5 plot'.

Now here's the rub.  'man 5 plot' typed in csh DOES provide the
requested manpage of plot(5).  So it does exist.

Right now I have a UI kludge written to compensate for this apparent
bug, but I would rather not have it.  I just want to be able to
type the manpage I want rather than tell it I need another section,
then type the section and then type the page, or even start off
with a case statement saying for a single number entered then branch
to ask for the page from that section.

Can someone please explain to me why this behave as it does and suggest
a fix?  Any help would be appreciated.

AtDhVaAnNkCsE

Dave
--
                   g l o r i o u sex i s t e n c e
EMAIL: tale@rpitsmts.bitnet, tale%mts.rpi.edu@rpitsgw, tale@pawl.rpi.edu
#! rnews           1118
Path: psuvm.bitn

hiebeler@rpics (Dave Hiebeler) (11/10/88)

In article <1698@imagine.PAWL.RPI.EDU> tale@pawl.rpi.edu writes:
>Okay, here's a segment of code that doesn't do exactly what everyone things
>it should.  It's for an csh-script.
> 
>set page = $<
>echo $page $#page		/* just for debugging
>if ( $page == 'q' ) exit
>man $page | less
>
>If I give it '5 plot', it does:
>5 plot 1
>if: expression syntax
>child of tty exited with return code 1
> 
  I think you want your third line to read:
if ( ${page[1]} == "q" ) exit

  (Note that just out of habit I use {} around variable-names, and double
quotes around strings... you probably don't need them, but I'm not sure.)
  I think your problem was the if was getting expanded to:
    if ( 5 plot == 'q' ) exit
----
Dave Hiebeler      Internet: hiebeler@cs.rpi.edu  (preferred address)
R.D. Box 225A                userfrzk%mts@itsgw.rpi.edu
Chatham, NY 12037    Bitnet: userfrzk@rpitsmts.bitnet
  "xue zai xao"     "...I can't remember what I was going to say..."

chris@mimsy.UUCP (Chris Torek) (11/10/88)

[apologies for all the quoting; I could not trim much out]
>In article <1698@imagine.PAWL.RPI.EDU> tale@pawl.rpi.edu writes:
>>set page = $<
>>echo $page $#page		/* just for debugging
>>if ( $page == 'q' ) exit
>>man $page | less
>>
>>If I give it '5 plot', it does:
>>5 plot 1
>>if: expression syntax
>>child of tty exited with return code 1

In article <1702@imagine.PAWL.RPI.EDU> hiebeler@rpics (Dave Hiebeler) writes:
>  I think you want your third line to read:
>if ( ${page[1]} == "q" ) exit

This still fails.

>  (Note that just out of habit I use {} around variable-names, and double
>quotes around strings... you probably don't need them, but I'm not sure.)

You need the quotes, but not where you put them:

>  I think your problem was the if was getting expanded to:
>    if ( 5 plot == 'q' ) exit

This is exactly the problem; to circumvent it, use

	if ("$page" == q) exit

or

	if ($page:q == q) exit

It is not necessary to quote the `q' that comes after the `==' in
this case, since it contains no special characters.  (It does not
hurt to quote it, of course.)
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris@mimsy.umd.edu	Path:	uunet!mimsy!chris