Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: #! problem



"Bart Schaefer" wrote:
> On Jan 15, 10:37am, Peter Stephenson wrote:
> } Subject: #! problem
> }
> } Somebody here tried something like:
> } 
> } #!/bin/zsh -f    
> } #            ^^^^empty spaces added here
> 
> As opposed to ... full spaces?

mmph.

> 2.  Stop parsing options at whitespace, and completely ignore it and
>     all the characters that come after it.  I believe BSD 4.2 csh did
>     this, if I'm remembering correctly my early days of feeling my way
>     through scripting.
> 
> 3.  As (2), but issue an error if there's anything other than whitespace
>     in the trailing part.  I think this is the most reasonable choice, as
>     it doesn't silently drop stuff from the #! line (which was mystifying
>     when it happened in csh, which is why I'm pretty sure I remember it).

This sounds OK to me, and that's what I've written.

There's one common case (common to me, anyway, I never realised it
wasn't going to work) which isn't handled:

#!/bin/zsh -f -*-ksh-*-

(important if you don't like the new shell-mode in Emacs.)  Looks like
I'll have to get used to writing

#!/bin/zsh -f-*-ksh-*-

which also works as the second - terminates processing.  I suppose
everybody else knew that already.

*** Doc/zsh.texi.opt	Thu Jan 16 09:51:24 1997
--- Doc/zsh.texi	Thu Jan 16 10:33:55 1997
***************
*** 5483,5488 ****
--- 5483,5499 ----
  the specification of option names by glob patterns, clashes with the use of 
  @samp{-m} for setting the @code{MONITOR} option.
  
+ @noindent
+ Note also that whitespace at the end of an otherwise valid option
+ string is ignored.  This is provided for the case when a zsh script is
+ invoked via a line of the form
+ 
+ @code{#!/bin/zsh -@var{option-string}}
+ 
+ @noindent
+ as many systems pass the text following the interpreter name with no
+ further processing.  If any other text follows the whitespace an error
+ is signalled.
  
  @node Shell Builtin Commands, Programmable Completion, Options, Top
  @chapter Shell Builtin Commands
*** Doc/zshoptions.man.opt	Thu Jan 16 09:51:19 1997
--- Doc/zshoptions.man	Thu Jan 16 10:33:01 1997
***************
*** 649,651 ****
--- 649,663 ----
  .BR unsetopt ,
  allowing the specification of option names by glob patterns,
  clashes with the use of \-\fBm\fP for setting the MONITOR option.
+ .PP
+ Note also that whitespace at the end of an otherwise valid option
+ string is ignored.  This is provided for the case when a zsh script is
+ invoked via a line of the form
+ .PP
+ .nf
+ #!/bin/zsh \-\fIoption_string\fP
+ .fi
+ .PP
+ as many systems pass the text following the interpreter name with no
+ further processing.  If any other text follows the whitespace an error
+ is signalled.
*** Src/init.c.opt	Wed Jan  8 11:13:10 1997
--- Src/init.c	Thu Jan 16 10:31:15 1997
***************
*** 205,210 ****
--- 205,211 ----
  
      /* loop through command line options (begins with "-" or "+") */
      while (*argv && (**argv == '-' || **argv == '+')) {
+ 	char *args = *argv;
  	action = (**argv == '-');
  	if(!argv[0][1])
  	    *argv = "--";
***************
*** 237,242 ****
--- 238,251 ----
  		    zerr("no such option: %s", *argv, 0);
  		else
  		    dosetopt(optno, action, 1);
+ 		break;
+ 	    } else if (isspace(**argv)) {
+ 		/* zsh's typtab not yet set, have to use ctype */
+ 		while (*++*argv)
+ 		    if (!isspace(**argv)) {
+ 			zerr("bad option string: `%s'", args, 0);
+ 			exit(1);
+ 		    }
  		break;
  	    } else {
  	    	if (!(optno = optlookupc(**argv))) {

-- 
Peter Stephenson <pws@xxxxxx>       Tel: +49 33762 77366
WWW:  http://www.ifh.de/~pws/       Fax: +49 33762 77413
Deutsches Elektronen-Synchrotron --- Institut fuer Hochenergiephysik Zeuthen
DESY-IfH, 15735 Zeuthen, Germany.



Messages sorted by: Reverse Date, Date, Thread, Author