[comp.sys.amiga.tech] Elinating the 'rx' from AREXX

UH2@PSUVM.BITNET (Lee Sailer) (08/10/89)

On IBM's CMS (the home of the original REXX) there is a kludgy but simple
convention for distinguishing REXX files from the older EXEC files which
could be used to distinguish AREXX from AmigaDOS scripts, too.  On CMS,
if the script starts with a comment on line one, then it is REXX.  This
is perhaps similar to the UNIX convention of putting (something like)
#!/bin/sh at the beginning of a script to tell the C shell to use the
Bourne shell, instead.

So, in short:

If the first line of an AmigaDOS script is

/* AREXX */

then AmigaDOS hands the script over to AREXX and bails out.

                                                             lee

UH2@PSUVM.BITNET (Lee Sailer) (08/10/89)

On IBM's CMS (the home of the original REXX) there is a kludgy but simple
convention for distinguishing REXX files from tci older EXEC files which
could be used to distinguish AREXX from Amigar &r scripts, too.  On Cex.S,
if the script starts with a comment ol
#is perhaps similar to the the modcconvention of putting (something like)
#!/bin/sh at the beginning of a script to tell the C shell to use the
Bourne shell, instead.

So, in short:

If the first line of an AmigarOS script is

/* AREXX */

then Amigar &r hands the script @at@to AREXX and bails out.

     Cby mo.b b pC C b                   leee fu

addison@pollux.usc.edu (Richard Addison) (08/13/89)

In article <89222.093949UH2@PSUVM> UH2@PSUVM.BITNET (Lee Sailer) writes:
>On IBM's CMS (the home of the original REXX) there is a kludgy but simple
>convention for distinguishing REXX files from the older EXEC files which
>could be used to distinguish AREXX from AmigaDOS scripts, too.  On CMS,
>if the script starts with a comment on line one, then it is REXX.  This
>is perhaps similar to the UNIX convention of putting (something like)
>#!/bin/sh at the beginning of a script to tell the C shell to use the
>Bourne shell, instead.

If I remember correctly, /bin/sh is the default shell for executing scripts
unless another shell is specified on the first line.

I'd like something of this ilk for AmigaDOS.  That way, we can support other
script interpreters that launch automatically.  Like PERL for instance!

Richard Addison
"Who is this guy?  And why is he posting so much all of the sudden?"

hans@nlgvax.UUCP (Hans Zuidam) (08/13/89)

addison@pollux.usc.edu (Richard Addison) writes:
>If I remember correctly, /bin/sh is the default shell for executing scripts
>unless another shell is specified on the first line.
Nope.

A UNIX shell looks at the first two bytes of the file you try to execute.
These two bytes together make up the 'magic word'. Each UNIX machine should
have its own magic words assigned. See /usr/include/sys/exec.h on a Sun or
Ultrix machine, on SysV it is somewhere else (a.out.h?).

When the magic word is not that of a code (executable) file the exec call to
the kernel will fail and the current shell assumes the file is a script and
tries to interpret it accordingly. Try this by executing a Sun binary on a
VAX or vice versa. You will get a syntax error from the shell.

Now the '#!' combination is a BSD special. It is documented nowhere (at
least the last time I looked 2 years ago ;-) ). When the first two
characters of a file passed to the loader are '#!', the *loader* takes
everything upto the fist newline as the name of an executable to pass the
rest of the file to. The executable is started and the current file is
passed on its standard input.

In my humble opinion this is not how the Amiga should do it. The Amiga
way of doing things would be to have a separate process for each loader
format, just as there is a separate task for each device instantation,
for each (2 :-) ) file system and so on. A much more opener design would
be to have a hierarchy of loaders with one master which knows how to
scatter load segments. If it couldn't load a file (because it is not an
executable) it would pass the file on to the next in the chain. This
could effectively remove the dependency between a command interpreter
and the rest of the system. Please not that I am *not* saying that it
is easy to design such a sub-system, but I have faith in the expertise
of Amiga's sw designers (;-) ).

By line:
The UNIX ps and /dev/kmem and /unix setup is *not* elegant. Someone said
it was, but I urge you to read the first article on theedesign of UNIX by
K&R in the BTJ (Bell Technical Journal). They chose for /dev/kmem because
in that way you don't have to supply all sorts of system-calls to get
information on the state of the kernel, Thus saving space. Back in the
old days it quite normal to patch the kernel with adb to modify an option.
On the Amiga running down lists is quite ok. They (and the operations on
lists) are standarised. The exact reference to the article is left as an
excersise for the interrested reader, as they say.

						Hans

Opinions above are mine, of course. Spelling errorz are probably cosed
by an over enthusiastic vi macro.
-- 
Hans Zuidam                                    E-Mail: hans@pcg.philips.nl
Philips Telecommunications and Data Systems,   Tel: +31 40 892288
Project Centre Geldrop, Building XR
Willem Alexanderlaan 7B, 5664 AN Geldrop       The Netherlands

shadow@pawl.rpi.edu (Deven T. Corzine) (08/13/89)

addison@pollux.usc.edu (Richard Addison) writes:

Richard> If I remember correctly, /bin/sh is the default shell for
Richard> executing scripts unless another shell is specified on the
Richard> first line.

Yep.

On 13 Aug 89 09:48:49 GMT, hans@nlgvax.UUCP (Hans Zuidam) said:

Hans> Nope.

And nope back to you.

Hans> A UNIX shell looks at the first two bytes of the file you try to
Hans> execute.  [...]  When the magic word is not that of a code
Hans> (executable) file the exec call to the kernel will fail and the
Hans> current shell assumes the file is a script and tries to
Hans> interpret it accordingly. Try this by executing a Sun binary on
Hans> a VAX or vice versa. You will get a syntax error from the shell.

FALSE.  If the magic number does not match, and there is no #!
interpreter specified, the exec call assumes /bin/sh as an
interpreter.  The syntax errors you get are bourne shell errors, from
the shell execve() created, NOT your current shell.

For example, if you have a csh shell script, and are using csh,
executing the csh script will try to interpret it with sh unless you
begin the file with "#!/bin/csh".  Only typing "source <file>" will
make the current shell execute the commands.

Hans> Now the '#!' combination is a BSD special. It is documented
Hans> nowhere (at least the last time I looked 2 years ago ;-) ). When
Hans> the first two characters of a file passed to the loader are
Hans> '#!', the *loader* takes everything upto the fist newline as the
Hans> name of an executable to pass the rest of the file to. The
Hans> executable is started and the current file is passed on its
Hans> standard input.

Under SunOS, #! is documented in the execve(2) man page.  The "loader"
is part of the execve() system call.  It takes an interpreter path,
optional args, tacks on the argv[0] filename of the script, and sets
stdin to the script as well.  If no magic number matches, and no
interpreter is specified, it assumes /bin/sh and continues.

Hans> In my humble opinion this is not how the Amiga should do it.

In my opinion, this IS how the Amiga should do it.

Hans> The Amiga way of doing things would be to have a separate
Hans> process for each loader format, just as there is a separate task
Hans> for each device instantation, for each (2 :-) ) file system and
Hans> so on.

You are a sick puppy.  [:-)]

Hans> A much more opener design would be to have a hierarchy of
Hans> loaders with one master which knows how to scatter load
Hans> segments. If it couldn't load a file (because it is not an
Hans> executable) it would pass the file on to the next in the chain.

A linked list of possible loading functions makes sense.  A task for
each is absurd.

Hans> On the Amiga running down lists is quite ok.

Exec's doubly-linked lists are efficient, dynamic and flexible.  But
this isn't relevant to #! and interpreters.

Deven
--
Deven T. Corzine        Internet:  deven@rpi.edu, shadow@pawl.rpi.edu
Snail:  2214 12th Street, Troy, NY 12180       Phone:  (518) 271-0750
Bitnet:  deven@rpitsmts, userfxb6@rpitsmts     UUCP:  uunet!rpi!deven
Simple things should be simple and complex things should be possible.

misterx@sun.ufnet.ufl.edu ( ) (08/15/89)

In article <SHADOW.89Aug13081959@pawl.rpi.edu> shadow@pawl.rpi.edu (Deven T. Corzine) writes:
>FALSE.  If the magic number does not match, and there is no #!
>interpreter specified, the exec call assumes /bin/sh as an
>interpreter.  The syntax errors you get are bourne shell errors, from
>the shell execve() created, NOT your current shell.

>For example, if you have a csh shell script, and are using csh,
>executing the csh script will try to interpret it with sh unless you
>begin the file with "#!/bin/csh".  Only typing "source <file>" will
>make the current shell execute the commands.

NOT TRUE :-)
If you have a csh script and you are using the csh, a comment as the
first line will give you a csh interpretation. If you do not have a
comment as the first line you will invoke /bin/sh to execute the script,
which of course will fail since the script was a csh script (unless it
is echo hello :-) I will not generalize this behavior to all UNIX shells
, but I have found many that will pass a script without a comment on the
first line to /bin/sh; otherwise the {insert a name} shell will
interpret the script.

BTW, a comment is any line that begins with a #.


--
"One, you lock the target. Two, you bait the line. Three, you slowly
spread the net. And four, you catch the man."
UUCP: ...!gatech!uflorida!sun.ufnet.ufl.edu!misterx  
Internet: misterx@sun.ufnet.ufl.edu | vishnu@pine.circa.ufl.edu