This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Shebang
cgd@broadcom.com writes:
> Totally off topic, but...
>
> At Mon, 8 Mar 2004 20:50:13 +0000 (UTC), prj@po.cwru.edu wrote:
>> > I suggest you write a wrapper program like this (only in C - you can't
>> > use a shell script as an #! interpreter):
>>
>> But you can do:
>> #!/usr/bin/env shell-script
>> ... input interpreted by shell-script here ...
>
> AFAIK not portably you can't:
>
> 217 [ldt-sj3-010] tmp % cat > shcat
> #!/bin/sh
> while read x; do
> echo $x;
> done
> 218 [ldt-sj3-010] tmp % chmod +x !$
> chmod +x shcat
> 219 [ldt-sj3-010] tmp % shcat
> foo
> foo
> 220 [ldt-sj3-010] tmp % cat > doshcat
> #!/usr/bin/env shcat
> foo
> bar
> 221 [ldt-sj3-010] tmp % chmod +x doshcat
> 222 [ldt-sj3-010] tmp % ./doshcat
> 223 [ldt-sj3-010] tmp % ./doshcat
> blah <- entered on stdin
> blah
> 224 [ldt-sj3-010] tmp %
Not sure what you are trying to show, but "./doshcat" is equivalent to
"/usr/bin/env shcat ./doshcat", which is the same as "shcat ./doshcat",
which looks exactly what Paul is trying to achieve.
> To quote the solaris manual page for execve:
>
> An interpreter file begins with a line of the form
>
> #! pathname [arg]
>
>
> where pathname is the path of the interpreter, and arg is an
> optional argument. When an interpreter file is executed, the
> system invokes the specified interpreter. The pathname
> specified in the interpreter file is passed as arg0 to the
> interpreter. If arg was specified in the interpreter file,
> it is passed as arg1 to the interpreter. The remaining argu-
> ments to the interpreter are arg0 through argn of the origi-
> nally exec'd file. The interpreter named by pathname must
> not be an interpreter file.
>
> note that last sentence.
None of the interpreters in your example are shebang scripts.
Andreas.
--
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux AG, Maxfeldstraße 5, 90409 Nürnberg, Germany
Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."