I write script in J for linux with #!
But script hang. After Control-D script echoed entered value. But normal ENTER only put cursor on new line.
#!/path/jconsole
a =. 1!:1]3
echo a
exit ''
You can't read a single line of text while j is in script mode, but you can schedule something to run the next time j returns to immediate execution mode by setting the immex phrase with 9!:27
and then setting the immex bit to 1 with 9!:29
. Here's an example:
#!/usr/bin/env j
NB. demo showing how to make a simple repl in j.
readln =: [: (1!:01) 1:
donext =: [: (9!:29) 1: [ 9!:27
main =: verb define
echo ''
echo 'main loop. type ''bye'' to exit.'
echo '--------------------------------'
while. (s:'`bye') ~: s:<input=:readln'' do.
echo ".input
end.
echo '--------------------------------'
echo 'loop complete. returning to j.'
NB. or put ( exit'' ) here to exit j.
)
donext 'main _'
The thing is that (1!:1)&3
reads till "end of file". In Linux, pressing ctrl-D sends the EOF signal.
If this is not what you're looking for, I'm afraid there there's nothing else but your "ugly trick"
a=. shell 'read foo; echo -n $foo'
as (1!:1)&1 only works during a session for some reason ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With