Utilities for process handling
🧭 Source: src/process.sh
This module contains helpers for script termination, signal handling, trap composition, deferred cleanup, and dry-run execution.
| Variable | Type | Description |
|---|---|---|
DYBATPHO_USED_ERR_HANDLER |
bool | Internal flag set after dybatpho::register_err_handler |
DYBATPHO_USED_KILLED_HANDLER |
bool | Internal flag set after dybatpho::register_killed_handler |
DRY_RUN |
string | When true-like, dybatpho::dry_run prints commands instead of executing them |
dybatpho::die— Log a fatal message and stop the current script or process.dybatpho::register_err_handler— Register the ERR trap handler used by dybatpho scripts.dybatpho::register_killed_handler— Register handlers for SIGINT and SIGTERM.dybatpho::register_common_handlers— Register both error and signal handlers.dybatpho::run_err_handler— Handle a command failure captured bydybatpho::register_err_handler.dybatpho::killed_process_handler— Handle SIGINT or SIGTERM received by the current process.dybatpho::trap— Append a command to one or more trap handlers without discarding existing traps._gen_finalize_command— Read the current trap command registered for a signal.dybatpho::cleanup_file_on_exit— Register a file or directory to be removed when the current shell exits.dybatpho::dry_run— Print a shell command instead of executing it whenDRY_RUNis enabled.
- This is the usual one-line setup at the top of scripts that want both error and signal handling
dybatpho::create_tempalready uses this internally, so call it directly only for custom temporary paths
- Pass a single shell command string because this helper executes the command with
eval
Log a fatal message and stop the current script or process.
🧾 Arguments
| Name | Type | Description |
|---|---|---|
$1 |
string | Message |
$2 |
number | Exit code, default is 1 |
🚦 Exit codes
$2: Exit the current shell with the requested code
Register the ERR trap handler used by dybatpho scripts.
Function has no arguments.
🧩 Variable sets
- DYBATPHO_USED_ERR_HANDLER
Register handlers for SIGINT and SIGTERM.
Function has no arguments.
🧩 Variable sets
- DYBATPHO_USED_KILLED_HANDLER
Register both error and signal handlers.
Function has no arguments.
Handle a command failure captured by dybatpho::register_err_handler.
🧾 Arguments
| Name | Type | Description |
|---|---|---|
$1 |
number | Exit code of last command |
Handle SIGINT or SIGTERM received by the current process.
🧾 Arguments
| Name | Type | Description |
|---|---|---|
$1 |
string | Signal |
Append a command to one or more trap handlers without discarding existing traps.
🧾 Arguments
| Name | Type | Description |
|---|---|---|
$1 |
string | Command to run when the signal is trapped |
$@ |
string | Signals to trap |
Read the current trap command registered for a signal.
🧾 Arguments
| Name | Type | Description |
|---|---|---|
$1 |
string | Signal name |
📤 Output on stdout
- Existing trap command, or an empty string when none is registered
Register a file or directory to be removed when the current shell exits.
🧾 Arguments
| Name | Type | Description |
|---|---|---|
$1 |
string | File or directory path |
Print a shell command instead of executing it when DRY_RUN is enabled.
🧪 Examples
DRY_RUN=true
dybatpho::dry_run "rm -rf ./build"
dybatpho::dry_run "ssh ${host} 'systemctl restart app'"
🧾 Arguments
| Name | Type | Description |
|---|---|---|
$@ |
string | Shell command string to run |
🌍 Environment variables
| Variable | Type | Description |
|---|---|---|
DRY_RUN |
string | Set to true, yes, on, or 0 to print commands instead of executing them |
📤 Output on stdout
- Show the command instead of executing it when
DRY_RUNis true