[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.3 Using FreeM for Shell Scripting

FreeM M routines can be used as shell scripts by providing a shebang line beginning with #!/path/to/freem as the first line of the routine. The following example presumes that FreeM is installed at ‘/usr/local/bin/freem’ and uses the USER namespace:

#!/usr/local/bin/freem
MYSCRIPT ;
 SET ^$JOB($JOB,"NAMESPACE")="USER"
 WRITE "This is output from an M routine used as a shell script.",!
 Q

Currently, the script needs to have a ‘.m’ file extension. You will also need to select an appropriate namespace in your script using the SET ^$JOB($JOB,"NAMESPACE")="<namespace>" command before attempting to call other routines or access globals.

You will also need to set the script’s permissions to executable in order for this to work:

$ chmod +x myscript.m

This document was generated on September 20, 2023 using texi2html 5.0.