david@doe.utoronto.ca (David Megginson) (04/29/91)
Thank you to every one who sent me mail. The solution to using the if [ <condition> ] syntax in sh is to link test to [. test is even smart enough that it looks for the ] if it is called as [. I am also interested in executable scripts. Right now, when I make a script executable, the kernel always seems to presume that it is for sh. I would like to have executable scripts like #! /usr/gnu/bin/gawk BEGIN { print "hello" } /bug/ { print "Oh no!" } END { print "bye" } If this script were called "buggy", and I chmod'd it to make it executable, I would expect it to run under gawk, but the kernel still gives it to sh (can't find BEGIN...). Any advice, or is this another incredible dumb question? -- //////////////////////////////////////////////////////////////////////// / David Megginson david@doe.utoronto.ca / / Centre for Medieval Studies meggin@vm.epas.utoronto.ca / ////////////////////////////////////////////////////////////////////////
jms@cs.vu.nl (Jan-Mark) (04/30/91)
In article <1991Apr29.110459.25477@doe.utoronto.ca>, david@doe.utoronto.ca (David Megginson) writes: #> #> Thank you to every one who sent me mail. The solution to using the #> #> if [ <condition> ] #> #> syntax in sh is to link test to [. test is even smart enough that it #> looks for the ] if it is called as [. #> #> I am also interested in executable scripts. Right now, when I make a #> script executable, the kernel always seems to presume that it is for #> sh. I would like to have executable scripts like #> #> #! /usr/gnu/bin/gawk #> #> BEGIN { print "hello" } #> #> /bug/ { print "Oh no!" } #> #> END { print "bye" } #> #> If this script were called "buggy", and I chmod'd it to make it #> executable, I would expect it to run under gawk, but the kernel still #> gives it to sh (can't find BEGIN...). Any advice, or is this another #> incredible dumb question? To some kernels #! is a magicnumber. If a file has #! as first two bytes, the rest of the line is put into an array and used in an ``system ()'' call. So hack the kernel is you want this! But are you sure you DO want this, remember; small is ..... Jan-Mark. -- (:> jms (_) ========""======
HBO043%DJUKFA11.BITNET@cunyvm.cuny.edu (Christoph van Wuellen) (04/30/91)
well by NO MEANS this is something that affects the kernel.. try looking at MM or sh. C.v.W.
awb@uk.ac.ed.aipna (Alan W Black) (04/30/91)
In article <9818@star.cs.vu.nl> jms@cs.vu.nl (Jan-Mark) writes:
#> [ other stuff deleted ]
#>
#> I am also interested in executable scripts. Right now, when I make a
#> script executable, the kernel always seems to presume that it is for
#> sh. I would like to have executable scripts like
#>
#> #! /usr/gnu/bin/gawk
#>
#> BEGIN { print "hello" }
#>
#> /bug/ { print "Oh no!" }
#>
#> END { print "bye" }
#>
#> If this script were called "buggy", and I chmod'd it to make it
#> executable, I would expect it to run under gawk, but the kernel still
#> gives it to sh (can't find BEGIN...). Any advice, or is this another
#> incredible dumb question?
To some kernels #! is a magicnumber. If a file has #! as first
two bytes, the rest of the line is put into an array and used
in an ``system ()'' call. So hack the kernel is you want this!
But are you sure you DO want this, remember; small is .....
Jan-Mark.
(:> jms
(_)
========""======
The gnu shell Bash actually checks for #! in the file it is about to
execute so this technique does work when using bash (available on
request). This surprised me as I thought Minix wouldn't do this but
then realised that I has been using #! in my shell scripts for ages
and it always worked. On investigation I saw that bash could deal
with this itself without any kernel change. (I'm sure this is
the right thing for bash to do though :-)
Alan
Alan W Black 80 South Bridge, Edinburgh, UK
Dept of Artificial Intelligence tel: (+44) -31 650 2713
University of Edinburgh email: awb@ed.ac.uk
"Hat, Eprom, Wilf" <CD2HDP17%CR83.STAFPOL.AC.UK@pucc.princeton.edu> (04/30/91)
sorry about this, but its been so long since i used this list, I have lost the instruction, and cant remember how to sign off, or which address to send it to, can someone tell me please?? Pete
gpvos@cs.vu.nl (Gerben 'P' Vos) (05/01/91)
HBO043%DJUKFA11.BITNET@cunyvm.cuny.edu (Christoph van Wuellen) writes: >well by NO MEANS this is something that affects the kernel.. >try looking at MM or sh. Yes, in MM. No, not in sh -- that's The Wrong Thing(tm) to do, if you want to be compatible with those Unix boxen that support the #! line. They do it in the kernel, so when you do exec() from within a program, the #! line is also honoured (an exec() call doesn't involve the shell). Of course, implementing it in the shell, like bash does, is a neat hack to emulate it on systems that don't have #! interpreting in the OS itself, but IMHO, if you want to do it right, change the OS (in this case, MM). . . . . . . . . . . . . . . . . . . . . . . . . . . . G e r b e n V o s <>< Aconet: BIGBEN!Gerben Vos Internet: gpvos@cs.vu.nl R.I.P. Radio Canada International 1942-1991