Multiline shebang: Difference between revisions

Content added Content deleted
(add matlab shebang)
Line 328: Line 328:


Note that we've left off the onfail handler within J, and just used a minimal definition to give us a non-zero exit code for the error case. Mostly, the assumption here would be that the error message would not be interesting, and that any failure should be handled by a retry. But you could replace the exit on error line here with the full definition and 9!: preparatory bit from the previous example and you could also of course change the 1!:2&2 lines (1!:2&2 is the "low-level" write to stdout mechanism for J - and, yes, those numbers are part of the definition of the language - or at least the "Foreigns" part of the language - note that ultimately all computer languages resolve to things which can be thought of as numbers or sequences of numbers, though some people will vigorously assert other things).
Note that we've left off the onfail handler within J, and just used a minimal definition to give us a non-zero exit code for the error case. Mostly, the assumption here would be that the error message would not be interesting, and that any failure should be handled by a retry. But you could replace the exit on error line here with the full definition and 9!: preparatory bit from the previous example and you could also of course change the 1!:2&2 lines (1!:2&2 is the "low-level" write to stdout mechanism for J - and, yes, those numbers are part of the definition of the language - or at least the "Foreigns" part of the language - note that ultimately all computer languages resolve to things which can be thought of as numbers or sequences of numbers, though some people will vigorously assert other things).

=={{header|MATLAB}}==

Unlike Octave, MATLAB has no built-in support for shebangs. In fact, several tricks are required to even approximate a shebang, due to the byzantine way that MATLAB structures scripts and function files.

~/bin/shmatlab%:

<lang bash>#!/bin/sh
matlab -nojvm -nodisplay -nosplash -r "varargin = regexp('${1+"$@"}', ' ', 'split'); nvarargin = length(varargin); run('$1'); exit" | tail -n +16
</lang>

args.m:

<lang matlab>'shmatlab'% $0 ${1+"$@"}
'exit';

for i = 1:nvarargin
disp(varargin{i});
end</lang>

Example:

<pre>
$ ./args.m a b c
./args.m
a
b
c
</pre>


=={{header|OCaml}}==
=={{header|OCaml}}==