Multiline shebang: Difference between revisions

m
Line 203:
<lang J>#!/bin/sh
# 0 :0
echo unix shell commands go here
echo presumably this will condition the environment
echo for example:
cd working-directory
echo or maybe you want to modify $PATH, ... whatever...
echo then start up J:
exec jconsole "$0" "$@"
)
 
Line 247:
<lang J>#!/bin/sh
# 0 :0
echo unix shell commands go here
echo presumably this will condition the environment
echo for example:
cd working-directory
echo or maybe you want to modify $PATH, ... whatever...
echo then start up J:
if jconsole -jprofile "$0" "$@"; then
echo success
else
echo failure
fi
exit $?
)
 
Line 273:
 
The exit $? line tells the shell interpreter to ignore the J part of the file, and the $? reuses J's exit code as the exit code from the shell instance.
 
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|OCaml}}==
6,951

edits