• Increase font size
  • Default font size
  • Decrease font size
Home Software SysFunc Sysfunc User's Guide

Sysfunc User's Guide

E-mail Print
Read : 1,511 times
(0 votes, average 0 out of 5)



Loading the library

The library is loaded using the following directive :

. sysfunc

assuming that /usr/bin is in your path.

Once the library is loaded, every sysfunc commands are available, prefixed with the 'sf_' string.

Calling a single function

It is possible to call a single function without preloading the library. The syntax to use is :

sysfunc <command> [args]

where <command> is the name of a sysfunc function to call, without the'sf_' prefix.

Example :

The following line creates or updates the 'myvar' DB variable with the current time :

sysfunc db_set_timestamp myvar 
It is similar to :
. sysfunc


    sf_db_set_timestamp myvar

The second form will be preferred when using several function calls in a script, as it is faster and avoids specifying 'sysfunc ' before every commands. The first form is easier to use when calling a single command, from the command line for instance.

Checking whether the library is loaded

The sf_loaded function checks if the library is loaded. When using this function, you must redirect stderr to /dev/null to avoid displaying an error when the library is not loaded (when the library is not loaded, the function won't be found).

The syntax to use is:

sf_loaded 2>/dev/null

This sets $? to 0 if the library is loaded, and to 1 if not. So, you can conditionally load the library using a line like :

sf_loaded 2>/dev/null || . sysfunc

This line causes the library to be loaded only if it was not done already.

:note Tip: When dealing with a set of several shell scripts, include such a directive at the beginning of every script which use sysfunc functions. This way, you ensure that the sysfunc commands are available when you need them, but the library is loaded only once.

 

Please login or register to add a comment