At 09:21 -0800 2007/11/27, efittery wrote:
I am looking for informtion on how to make a j executable that will process
command line arguments.
As an example the file test is:
-----------------------------
#!/home/efittery/bin/jconsole
testValue =: 'doing test'
echo testValue
exit ''
-----------------------------
to execute the file test, you just type ./test (in unix that is ).
this will display:
doing test
-----------------------------
How can you pass an argument in to ./test to initialize testValue for
display?
--
I need to make a wiki page for this, but here is a repeat
of a message I have posted several times starting 7 years ago
-----
At 16:51 -0700 2003/05/22, Joey Tuttle wrote:
First a big THANK YOU to Jsoftware for adding the tweak of ~/.jhistory
to remember readline history in Linux. This is just terrific and makes
using jconsole even more of a joy.
Thinking about console stuff, I did some work on updating some of my
#! scripts. In particular trying to deal with (optional) standard input
as received in a Unix pipeline expression. Going back 3 years -
......
And then a verb that I first created 3 years ago, I updated to be -
getargs =: 3 : 0
ARGV getargs y.
:
require 'jmf'
argb =. (]`(([: < 1: {. }.) , [: < 2: }. ])@.('-'"_ = {.))&.> x.
NB. The above boxes parms (elements starting with "-" returning name;value
parm =. 32 = ;(3!:0)&.> argb
((-. parm)#argb);(>parm#argb);(". ({. 0 = >c_isatty_jmf_ 0)#'stdin ''''')
)
The purpose of getargs is to pick up "options" from the command
line of a #! script as distinct from "file names" and standard input.
Such a script might look like "stest" below -
[EMAIL PROTECTED] jkt]$ cat stest
#! /usr/local/bin/ja
3 : 0 ARGV
echo getargs 'not here yet'
exit 0
)
[EMAIL PROTECTED] jkt]$
Using it shows variations of picking up command line stuff. In these
examples "stest" returns a modified ARGV, option parameters, and standard
input (parms and stdin are empty if there is none) -
[EMAIL PROTECTED] jkt]$ ./stest
+---------------------------+++
|+-----------------+-------+|||
||/usr/local/bin/ja|./stest||||
|+-----------------+-------+|||
+---------------------------+++
[EMAIL PROTECTED] jkt]$ ./stest -d"#" -p"slice & dice" file.in file.out
+--------------------------------------------+----------------++
|+-----------------+-------+-------+--------+|+-+------------+||
||/usr/local/bin/ja|./stest|file.in|file.out|||d|# |||
|+-----------------+-------+-------+--------+|+-+------------+||
| ||p|slice & dice|||
| |+-+------------+||
+--------------------------------------------+----------------++
[EMAIL PROTECTED] jkt]$ date | ./stest -d"#" -c4 file.in file.out -p"slice &
dice"
+--------------------------------------------+----------------+-----------------------------+
|+-----------------+-------+-------+--------+|+-+------------+|Thu
May 22 16:27:37 PDT 2003 |
||/usr/local/bin/ja|./stest|file.in|file.out|||d|# ||
|
|+-----------------+-------+-------+--------+|+-+------------+|
|
| ||c|4 ||
|
| |+-+------------+|
|
| ||p|slice & dice||
|
| |+-+------------+|
|
+--------------------------------------------+----------------+-----------------------------+
[EMAIL PROTECTED] jkt]$
Having the ability to determine if there is content in the "stdin buffer"
makes it convenient to write "user friendly" #! scripts - I would even
re-nominate it as a possible addition to externals (as I did 3 years ago).
The 'not here yet' argument to getargs is a thought about emulating
the "optstrings" argument to "getopts" in the sh/bash shells. The parsing
rules for optstrings allow multi-character option names (and require a
space delimiter to do that) but I find the simple facility of getargs
to be adequate for most purposes. Maybe the "real solution" is more
complex than my simplistic stuff...
This stuff is also very handy for Apache CGI scripts. Happy to see some
discussion on #! here - there aren't very many of us who use it, but it
is a very nice addition to scripts in Linux environments.
- joey
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm