Eduard,

You have just forgotten about "Щ" in your awesome one-liner, while the $replacing of "Ш" is excessive. So, it should look like that: 

 $tr($zcvt($replace($replace($tr(russian, "абвгдезийклмнопрстуфхыэАБВГДЕЗИЙКЛМНОПРСТУФХЫЭЖЦЧШЮЯжцчшюяьЬъЪ", "abvgdeziyklmnoprstufhyeABVGDEZIYKLMNOPRSTUFHYE婨味䍨卨奵奡穨瑳捨獨祵祡"),"щ","shch"),"Щ","Shch"),"O","UnicodeBig"),$c(0))

Another part of my solution was published as a comment here.

This trick with answers (fin.txt) and messages (fout.txt) files was possible with background job only as only this kind of Caché processes allows the separation principal-input device from principal-output one.

Controlling the execution state would not be so easy in this case as fout.txt is kept opened during the execution of JRNREST. I partially bypass this limitation looping my dejournaling activity for each journal file I need to restore and feeding JRNREST with only one file on each iteration  (pLast = pFirst); so it's possible to report the restore state of each file that has been restored with very modest delay as the restoration of one journal file is usually a quick process.

HTH and happy coding to you!

Robert,

As to (simulated) named arguments approach:

(+): Good readability.

(-):  We should be pretty sure that values would not contain separators, neither "=" nor ":", although screening of them is not a very hard problem ("\=", "\:", "\\"). 

(-): Handling binary data (e.g., $list or $bit) seems to be more serious problem. In this case it seems that one argument structured as $lb($lb("name1",value1),...$lb("nameN",valueN)) is better option.

David,

you can try

set rc=$zf(-1,"export MYVAR="_someValue)

while it would hardly work as Caché process environment will be destroyed after the process halt. Honestly, I've never tried it.

I usually use signal files to pass values back from Caché, as it was shown in the 1st sample here: How to return the status code of Cache process to OS shell script?

See Timothy Leavitt's answer to the same post for another option which is more convenient when you are to return numeric values.

No, it works and all installations but yes, it needs 8 Bit  characters

It needs Unicode characters as well, otherwise it fails. Just compare 8 bit instance run: 

USER>w "IsUnicode = ",$zbitget($zversion(0),1)
IsUnicode = 0
USER>s x="f i=1:1:100 w:i#3=0 ""Fizz"" w:i#5=0 ""Buzz"" w:'$x i w ! " w $l(x)
54
USER>s xx=$zwpack(x)
 
S xx=$ZWPACK(x)
^
<WIDE CHAR>

with Unicode one:

USER>w "IsUnicode = ",$zbitget($zversion(0),1)
IsUnicode = 1
USER>s x="f i=1:1:100 w:i#3=0 ""Fizz"" w:i#5=0 ""Buzz"" w:'$x i w ! " w $l(x)
54
USER>s xx=$zwpack(x)
USER>x $zwunpack(xx)
1
2
Fizz
...

Hi James,

Agree with you, parsing terminal output is not the smartest solution. I always try to avoid it using intermediate files. E.g. (from real life):

rm -f $mydir/db_temp
NspToCheck=$nspace

csession $instance -U%SYS << EOF > /dev/null
set fn="$mydir/db_temp"
o fn:("WNS"):1 u fn
try {
  zn "$NspToCheck"
  w \$s(\$zu(5)=\$zcvt("$NspToCheck","U"):\$zutil(12,""),1:"$NspToCheck")
} catch {
  w \$p(\$ze,">")_">"
}
c fn
h
EOF

DbQms=$(cat "$mydir/db_temp")

Here the default DB of the namespace $NspToCheck (or $ZError code) is written to $mydir/db_temp file, than it goes to $DbQms shell variable and processed as needed.

Initial answer was amended.

Your sample works for me: 

USER>s rc = $zf(-100,"/SHELL","pwd")
/cachesys/mgr/user

USER>w $zv
Cache for UNIX (Ubuntu Server LTS for x86-64) 2017.2.2 (Build 865U) Mon Jun 25 2018 10:48:26 EDT

What Caché version are you using? $zf(-100) was added in 2017.2.1 (Build 801_3).  For older versions use $zf(-1 or -2), while upgrade to latest Caché (or even IRIS?) release would probably be the better choice.

The simplest way to interact from within bash with Caché looks like this: 

#!/bin/bash
...
csession TEST -U%SYS << EOF
set \$namespace="%SYS"
write ##class(Security.System).AutheEnabledGetStored("SYSTEM")
halt
EOF
... next line of your bash script ...

Output of Caché `write` and `zwrite` commands will go to STDOUT. As usual, you can redirect it wherever you want, e.g.

csession TEST -U%SYS << EOF >> /home/james/mysession.log

As parsing csession log can be a nasty task, I usually try to avoid it by construct:

#!/bin/bash
...
tf=/home/file.tmp
...
csession TEST -U%SYS << EOF > /dev/null
open $tf:("NWS"):1 use $tf
write ##class(Security.System).AutheEnabledGetStored("SYSTEM")
close $tf
halt
EOF
...
result=$(cat "$tf")