Hi All,
Here's a little script I put together to make J easily accessible on the
UNIX command line. It's really handy, especially with J's terseness.
Cheers,
Mike
----- Example usage (on UNIX command line)
$ echo '-1 2 3' | jio '+/'
4
$ jio '_2 + i. 5'
-2 -1 0 1 2
----- The jio script itself
#!/usr/bin/env bash
# Print usage and exit
Usage() {
>&2 echo "Usage : jio J-EXPR"
>&2 echo "Example : echo '1 2 3' | jio '+/%#'"
>&2 echo "Example : jio 'i. 3'"
exit -1
}
# Parse command line
if [ $# -eq 0 ]; then
>&2 echo "ERROR: Argument J-EXPR is missing."
>&2 echo ''
Usage
elif [ $# -ne 1 ]; then
>&2 echo "ERROR: Too many arguments."
>&2 echo ''
Usage
fi
jexpr=$1
# If STDIN is present, echo that, otherwise empty string
Arg() {
if read -t 0; then
read x
echo $x | sed 's/-/_/g'
fi
}
# Forward to jconsole
echo "($jexpr) `Arg`" | jconsole.exe | sed -n -e 's/_/-/g' -e '$!p'
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm