The shellscript statement executes a UNIX shell script.
Parameters
This statement has four parameters:source – UNIX shell script (source code). Note: It is very convenient to use “pipe” delimiters for this parameter, for example |||script|||
. This eliminates needing to worry about the delimiters that occur in the script itself.
result – Name of the field or variable in which the result of the script will be placed. This result is any output sent to the standard console ouptut. If this parameter is not supplied the result will be placed in the global variable ScriptResult.
timeout – Maximum amount of time the script will be allowed to run (in seconds). If this option is not specified you can set the default using the scripttimeout statement. If this default has never been set the default is 60 seconds.
password – Password (if empty then will prompt for password if needed.)
Description
This statement executes a UNIX shell script. Here is a simple example that displays a list of files in the Library folder.
local libraryFiles
shellscript |||cd ~/Library;ls -l |||,libraryFiles
displaydata libraryFiles
This example uses two shell commands: cd (change directory) and ls (list files). There are hundreds of different shell commands available. Describing all of these commands is beyond the scope of this documentation, but there are many books available, as well as numerous web resources.
Panorama formulas can be embedded in the script using special tags. To embed a Panorama formula use
$«formula»$
The formulas are calculated in advance, then embedded into the source code as constants. For example, the formula $«2*3»$
will be embedded into the program as 6
. The formula $«upper("hello world")»$
will be embedded as HELLO\ WORLD
.
In the case of text formulas any special characters will be encoded as necessary for a proper shell script literal. For example the formula $«{"}»$
will be embedded as "
.
To embed a Panorama formula with no quotes or translation use
^«formula»^
Note: If your script begins with ; then Panorama will run the script using the current bash profile (see usebashprofile, which you should run before calling the script with this option.)
Note: This statement was designed to replace the older executeunix and executesudounix (which are retained for compatibility with older databases). It and its equivalent function, shellscript(, are similar to the posixscript( function, but with some significant differences. When using the posixscript( function, no substitutions are performed on the script code, so you cannot embed Panorama variables and formulas into the code as described above (of course you can use a formula to build the code any way you want). Most importantly, the posixscript( function runs the script by using a native Cocoa method (NSTask) while the shellscript statement and shellscript( function use AppleScript, so the posixscript( function is faster. The shellscript statement and shellscript( function are retained for compatibility with legacy database applications, but posixstring( is recommended for new applications.
If no substitutions, timeout or password are specified, a statement in the form shellscript source,result
may usually be replaced by
result=posixscript(source)
See Also
History
Version | Status | Notes |
10.0 | No Change | Carried over from Panorama 6.0. |