How to call J (ijconsole) with a script automatically

邮差的信 提交于 2021-01-27 13:40:12

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!