Search code examples
argvj

Using command-line arguments in J


I know that ARGV represents the arguments. Can I type arguments after the filename in jqt.exe or does that only work in jconsole.exe. Executing the code regarding ARGV given in the J docs crashes J on my Win 10. An example would be welcome. I tried out 0 ". > ,. 2 }. ARGV from an earlier question on SO, but am not sure how to make it work.


Solution

  • Both jqt and jconsole read the command line arguments and box them:

    jqt script.ijs arg1 arg2
    
    
      ARGV
    ┌───┬──────────┬────┬────┐
    │jqt│script.ijs│arg1│arg2│
    └───┴──────────┴────┴────┘
    
    
      2}. ARGV
    ┌────┬────┐
    │arg1│arg2│
    └────┴────┘
    
      ] x =: > 3 { ARGV
    arg2
    

    example script:

    $ cat script.ijs
    x =: ". every 2 }. ARGV                                                                                                                
    echo +/ x 
    
    $ jqt script.ijs 1 2 3
    6