问题
I'm using the J programming language in Ubuntu, and I'd like to call a script automatically from the command line. I think this should be possible using the ijconsole command, but I don't know how to pass it a set of functions.
For instance, in perl, one would type:
perl -e 'print "Hello";'
Is there an equivalent method for J, using the ijconsole program? For instance:
ijconsole -e 'load "script.ijs"'
Thank you!
回答1:
Assuming ijconsole is in your path, you can run a script from the terminal command line as follows:
ijconsole script.ijs
If you want to run some commands (not in a script) then this will work:
ijconsole -js "echo 'Hello world'" "exit 0"
69
The command line options are documented in the J user manual.
回答2:
Shell script invocations of J scripts are documented in the J Shell Script page.
In a nutshell, all shell scripts can be directed to be run through an interpreter other than the default system shell (typically sh, bash, or zsh). This is done with the first line having a "shebang":
#!/path/to/interpreter arguments...
... remainder of script
For example, ruby scripts can be invoked with:
#!/usr/bin/env ruby
# ruby script ...
And, a J script can be invoked with:
#!/usr/bin/env jconsole
NB. process ARGV and do something
args=.2{ARGV
exit 0
Here is a complete example of a J script:
$ cat tst.js
#!/Applications/j64/bin/jconsole
9!:7'+++++++++|-' NB. set ascii box mode
echo 'ARGV=';ARGV NB. show ARGV contents
args=.2}.ARGV NB. de-head and return only the actual arguments
echo 'args=';args NB. show the actual args
exit''
and it's output when run:
$ ./tst.js foo bar bif
+-----+------------------------------+--------+---+---+---+
|ARGV=|/Applications/j64/bin/jconsole|./tst.js|foo|bar|bif|
+-----+------------------------------+--------+---+---+---+
+-----+---+---+---+
|args=|foo|bar|bif|
+-----+---+---+---+
来源:https://stackoverflow.com/questions/47897187/how-to-call-j-ijconsole-with-a-script-automatically