|
function | abspath (in path) |
| Get absolute path given a relative path. More...
|
|
function | execute (in options, in cmd, in args) |
| Execute command as subprocess. More...
|
|
function | exedir (out dir, in name) |
| Get directory of executable file. More...
|
|
function | exename (out file, in name) |
| Get name of executable file. More...
|
|
function | exepath (out path, in target) |
| Get absolute path of executable file. More...
|
|
function | import (in options, in module) |
| Import Bash module. More...
|
|
function | istarget (in target) |
| Determine whether a given build target is known. More...
|
|
function | match (in value, in pattern) |
| This function implements a more portable way to do pattern matching. More...
|
|
function | normpath (in path) |
| Clean path, i.e., remove occurences of "./", duplicate slashes,... More...
|
|
function | print_contact (in contact) |
| Print contact information. More...
|
|
function | print_version (in options, in name, in version) |
| Print version information including copyright and license notices. More...
|
|
function | qsplit (out var, in str) |
| Split (quoted) string. More...
|
|
function | realpath (in path) |
| Get canonical file path. More...
|
|
function | targetuid (out uid, in name) |
| Get UID of build target. More...
|
|
function | tostring (out var, in elements) |
| Build quoted string from array. More...
|
|
function | upvar (in var, in values) |
| Assign variable one scope above the caller. More...
|
|
function | upvars () |
| Assign variables one scope above the caller. More...
|
|
function execute |
( |
in |
options, |
|
|
in |
cmd, |
|
|
in |
args |
|
) |
| |
Execute command as subprocess.
This function is used to execute a subprocess within a Bash script.
Example:
# the next command will exit the current shell if it fails
# to prevent this, provide the --allow_fail option
execute --allow_fail ls /not/existing
# to make it explicit where the command-line to execute starts, use --
execute --allow_fail -- ls /not/existing
Note that the output of the command is not redirected by this function. In order to execute the command quietly, use this function as follows:
Or to store the command output in a variable including error messages use it as follows:
Note that in this case, the option –allow_fail has no effect as the calling shell will never be terminated. Only the subshell in which the command is executed will be terminated. Checking the exit code $? is in this case required.
- Parameters
-
[in] | options | Function options as documented below. |
[in] | cmd | Executable of command to run or corresponding build target name. This is assumed to be the first non-option argument or the argument that follows the special '–' argument. |
[in] | args | All remaining arguments are passed as arguments to the given command. |
- Options:
-f, –allow_fail | Allows the command to fail. By default, if the command returns a non-zero exit code, the exit() function is called to terminate the current shell. |
-v, –verbose [int] | Print command-line to stdout before execution. Optionally, as it is sometimes more convenient to pass in the value of another variable which controls the verbosity of the parent process itself, a verbosity value can be specified following the option flag. If this verbosity less or equal to zero, the command-line of the subprocess is not printed to stdout, otherwise it is. |
-s, –simulate | If this option is given, the command is not actually executed, but the command-line printed to stdout only. |
- Returns
- Exit code of subprocess.
function exepath |
( |
out |
path, |
|
|
in |
target |
|
) |
| |
Get absolute path of executable file.
This function determines the absolute file path of an executable. If no arguments are given, the absolute path of this executable is returned. If the given argument is a known build target name, the absolute path of the executable built by this target is returned. Otherwise, the named command is searched in the system PATH and it's absolute path returned if found. If the given argument is neither the name of a known build target nor an executable found on the PATH, an empty string is returned and the return value is 1.
- Parameters
-
[out] | path | Absolute path of executable file. |
[in] | target | Name/UID of build target. If no argument is given, the file path of the calling executable is returned. |
- Returns
- Nothing.
- Return values
-
0 | On success. |
1 | On failure. |
function import |
( |
in |
options, |
|
|
in |
module |
|
) |
| |
Import Bash module.
This function can be used to import, i.e., source, a named module, where the module is searched for in the directories specified by the BASHPATH
(environment) variable. Modules can be prepended by the names of the subdirectories they are located in relative to a directory listed in the BASHPATH
, where dots (.) can be used instead of slashes to separate the parts of the relative module path. A .sh
file name extension of the modules is appended to the module name when looking for a matching Bash module file. It must not be included in the module
name to avoid confusion with the dot used as path / submodule separator. The module name "utils.sh" thus translates to the file path "utils/sh.sh"!
Example:
import sbia.basis.core
import -o optional.module
if [ $? -eq 0 ]; then
echo "Module optional.module imported successfully"
else
echo "Module optional.module not found"
fi
- Note
- The directories listed in the
BASHPATH
must be absolute paths starting with a forward slash (/).
- Parameters
-
[in] | options | Option flags. The only possible option is -o. If this option is given before the module name, the function returns with return value 1 on error. Otherwise, it calls the exit function with this exit code. It can therefore be used for optional modules, which do not necessarily need to be imported. |
[in] | module | Name of the module to import (excl. .sh file name extension). |
- Returns
- Only on success or if the -o option is given. Otherwise it calls the exit function if an error occurs.
- Return values
-
0 | if the module was loaded successfully. |
1 | on error if -o option is given. |
function normpath |
( |
in |
path | ) |
|
Clean path, i.e., remove occurences of "./", duplicate slashes,...
This function removes single periods (.) enclosed by slashes or backslashes, duplicate slashes (/) or backslashes (), and further tries to reduce the number of parent directory references.
For example, "../bla//.//.\bla\\\\\bla/../.." is convert to "../bla".
- Parameters
-
- Returns
- Cleaned path.
function targetuid |
( |
out |
uid, |
|
|
in |
name |
|
) |
| |
Get UID of build target.
The UID of a build target is its name prepended by a namespace identifier which should be unique for each project.
This function further initializes the dictionary storing the information about the executable targets upon the first invocation. Reason to do it here is that every access to the dictionaries first calls this function to get the UID of a build target. Moreover, also this function needs to have the already initialized dictionaries to ensure that an already valid target identifier is not modified. As Bash does not provide hash tables, dictionary data structures, the imitation of these is necessary which, however, results in many eval() calls with noticeable impact on running time. Therefore, to decrease the time required to source the BASIS utilities, the required dictionary structure is initialized only upon first use.
- Parameters
-
[out] | uid | UID of named build target. |
[in] | name | Name of build target. |
- Returns
- Nothing.
- Return values
-
0 | On success. |
1 | On failure. |