[comp.unix.questions] shell or c-shell?

chen-dahe@CS.Yale.EDU (Dahe Chen) (03/24/90)

I am having trouble with a shell script I wrote (forgive me if it is trivial,
what can you blame for a naive user):

#! /bin/sh
#
MANPATH=/twolf7/dchen/man
if [ -f $MANPATH/"$1".1 ]
then
    nroff -man $MANPATH/"$1".1 | more
else
    /usr/ucb/man $1
fi

It works if I explicitly invode shell, i.e.,

% sh [-x] man xxx

but does not work when I do

% man xxx

which gives me

No manual entry for .

My login shell is csh. It looks like the latter calls c-shell instead of shell.
If it is true, how can I solve the problem. Thanks in advance.
Dahe Chen
internet:   dchen@twolf.ce.yale.edu
	    chen-dahe@cs.yale.edu
bitnet:	    dchen@yalevms

tr@samadams.princeton.edu (Tom Reingold) (03/24/90)

In article <20009@cs.yale.edu> chen-dahe@CS.Yale.EDU (Dahe Chen) writes:
$ I am having trouble with a shell script I wrote (forgive me if it is trivial,
$ what can you blame for a naive user):
$ 
$ #! /bin/sh
$ #
$ MANPATH=/twolf7/dchen/man
$ if [ -f $MANPATH/"$1".1 ]
$ then
$     nroff -man $MANPATH/"$1".1 | more
$ else
$     /usr/ucb/man $1
$ fi
$ 
$ It works if I explicitly invode shell, i.e.,
$ 
$ % sh [-x] man xxx
$ 
$ but does not work when I do
$ 
$ % man xxx
$ 
$ which gives me
$ 
$ No manual entry for .
$ 
$ My login shell is csh. It looks like the latter calls c-shell instead of shell.
$ If it is true, how can I solve the problem. Thanks in advance.

Is "." in the beginning of your path or at the end?  Did you rehash
after creating your man command?  Did you "chmod +x man"?  Try "./man
xxx" and see what happens.
--
Tom Reingold
tr@samadams.princeton.edu

chen-dahe@CS.YALE.EDU (Dahe Chen) (03/24/90)

In article <20009@cs.yale.edu> I write:
>I am having trouble with a shell script I wrote (forgive me ...)
>
>#! /bin/sh
>#
>MANPATH=/twolf7/dchen/man
>if [ -f $MANPATH/"$1".1 ]
>then
>    nroff -man $MANPATH/"$1".1 | more
>else
>    /usr/ucb/man $1
>fi
>
>It works if I explicitly invoke shell, i.e.,
>
>% sh [-x] man xxx
>
>but does not work when I do
>
>% man xxx
>
>which gives me
>
>No manual entry for .
>
>My login shell is csh. It looks like the latter calls c-shell instead of shell.
>If it is true, how can I solve the problem. Thanks in advance.

I forgot to say that I am using ULTRIX-32 version 3.0 and that any
other names for the shell script work in the c-shell. I am now puzzled
why the kernal can not determine correctly which shell to use if I use
that very name. Everything looks fine to me:

% ls -l ~/bin/man
-rwxr-xr-x  1 dchen         149 Mar 23 16:16 /twolf7/dchen/bin/man*
% which man
/twolf7/dchen/bin/man
% file ~/bin/man
/twolf7/dchen/bin/man:  /bin/sh script
% echo $PATH
.:/twolf7/dchen/bin:/usr/local/bin:/usr/ucb:/usr/bin:/bin:/etc:/usr/etc:/usr/new/mh


Can anyone enlighten me? Thanx.



----------------------
Dahe Chen
internet:   dchen@twolf.ce.yale.edu
	    chen-dahe@cs.yale.edu
bitnet:	    dchen@yalevms

tchrist@convex.COM (Tom Christiansen) (03/26/90)

In article <20009@cs.yale.edu> chen-dahe@CS.Yale.EDU (Dahe Chen) writes:
>I am having trouble with a shell script I wrote (forgive me if it is trivial,
>what can you blame for a naive user):
>
>#! /bin/sh
>#
>MANPATH=/twolf7/dchen/man
>if [ -f $MANPATH/"$1".1 ]
>then
>    nroff -man $MANPATH/"$1".1 | more
>else
>    /usr/ucb/man $1
>fi

Seeing what you're trying to do here, I would strongly recommend that you get
my perl rewrite of man using ndbm whatis databases, assuming you've both
perl and ndbm support.  I'll send it to you if you mail me a path that I
can hope to reply to, meaning either in Internet style or else a
non-mixed-mode address rooted at some very well-known site like uunet.

Following is a list of features my man affords you:

    *   almost always faster than standard man (try 'man me')

    *   take much less diskspace for catpages

    *   supports per-tree tmac macros

    *   compressed man and cat files

    *   user-definable man path via $MANPATH or -M (mine is set this way
          setenv MANPATH "$HOME/man:/usr/local/man:/usr/local/mh/man:/usr/man"

    *   user-definable section search order via -S or $MANSECT (so 
	you can get wait(2) before wait(1) if you want)

    *   $PAGER support

    *   looks up all the places you might find a man page (-w option)

    *   no limits on what subsections go where (if you want to add 7x, ok)

    *   support for multi-char sections like man1m/*.1m

    *   per man-tree tmac files

    *   ability to run man on a local file

    *   ability to easily troff (or preview) a man page

    *   recognizes Sun-style embedded filter directives for tbl and eqn

    *   does the right thing for man tree that don't have DBM whatis files

Here are some features of this version of makewhatis:

    *   it's faster.

    *   tries hard to make pretty output, stripping troff directives.

    *   doesn't blow up on more files in a man directory
        than the shell will glob.

    *   accepts troff string macros for the dashes in the
        the NAME section.

    *   prints a diagnostic for a malformed NAME section.

    *   detects linked (hard, soft, or via .so) man pages

    *   finds *all* references in the NAME section.

    *   recognizes MH's man macros (and .Sh from lwall).

    *   many other things that makewhatis used to do wrong


--tom
--

    Tom Christiansen                       {uunet,uiucdcs,sun}!convex!tchrist 
    Convex Computer Corporation                            tchrist@convex.COM
		 "EMACS belongs in <sys/errno.h>: Editor too big!"

paul@ixi.co.uk (Paul Davey) (03/28/90)

In articles <20009@cs.yale.edu> and <20050@cs.yale.edu> 
chen-dahe@CS.YALE.EDU (Dahe Chen) writes:

>>I am having trouble with a shell script I wrote (forgive me ...)
>>
>>#! /bin/sh
>>#
>>MANPATH=/twolf7/dchen/man

>>It works if I explicitly invoke shell, i.e.,
>>
>>% sh [-x] man xxx
>>
>>but does not work when I do
>>
>>% man xxx
>>
>>which gives me
>>
>>No manual entry for .
>>
>
>I forgot to say that I am using ULTRIX-32 version 3.0 and that any
>other names for the shell script work in the c-shell. I am now puzzled
					      ?^^^^^?
>why the kernal can not determine correctly which shell to use if I use
>that very name. 

Do you mean that it still gives errors if you rename the script foo ??
Dou you mean it works if you rename it foo? 
What happens if you call it from sh?
Do you have any aliases set up (for man) ??

>Everything looks fine to me:

Me too, from what's here, though I can't see how you are getting the error 
message "No manual entry for ."  

If it is running under csh, you would get an error at the line 
"MANPATH=/twolf7/dchen/man"


Try debugging with the flags to sh set in the file , ie
#!/bin/sh -xv 
etc

If this does not produce diagnostics then you'll know that the #! line is 
not being used for some reason.

For diagnostic purposes you could try 
csh -XV man xxx 
( The capitals will show you if your .cshrc is doing anything )

Some other points,

1) Delete the space after #! to make line 1 #!/bin/sh
However this doesn't stop scripts on my system (bsd 4.3 based)
		It's probably just me being superstitious! -:)
(I always close things up to be safe, though this may be a red herring)

2) If you still distrust the kernal remove all the initial comments. 
Executable text files are passed to /bin/sh automatically, though it's
good style to put them in explicitly.

In fact since even old machines did not have the #! notation 
an initial # (with no !) means use C shell

This is a common way of getting csh when you wanted sh 
however you seem to have the reverse.


-- 
					                     
 Regards,			paul@ixi.co.uk          IXI Limited          
	 Paul Davey		...!uunet!ixi!paul      62-74 Burleigh Street
				+44 224 462 132 (fax)   Cambridge  U.K.