How do you run a standalone ijs j file on Linux?

Viewed 279

I have been using j for a few weeks now and loving it. However, all of my work has been in the ijconsole. Does j provide a way to run .ijs files without using load? Similar to how you can simply run $python my_file.py?

I know for windows there exists jconsole.exe, but for Linux and OSx there doesn't seem to be the same option?

2 Answers

You should be able to run bin/jconsole with the .ijs file as the first command line argument.

Here's an example session, copied out of my terminal:

~/j64-807$ cat ex.ijs 
d =: 1+1
~/j64-807$ ./bin/jconsole ex.ijs 
   d
2

I figured out how to get my desired behavior from

https://www.jsoftware.com/help/user/hashbang.htm

The basic idea is to create a "unix script" that points to jconsole by using

#!/home/fred/j64-807/bin/jconsole

at the top of the .ijs file.

Then, you can echo any output you wish or use ARGV to read input.

Finally, call chmod +x your_script.ijs and run using ./your_script.ijs

You can copy the j interpreter files to new projects on servers etc and call them using bash.

So, a final example would be

#!/home/fred/j64-807/bin/jconsole
echo +/*:0".>,.2}.ARGV
exit''

Which computes the sum of squares of digits from command line arguments

Related