shellkitshellkit
Guide
API reference
Examples
Changelog
Releases
llms.txt
GitHub
  • 简体中文
  • English
Guide
API reference
Examples
Changelog
Releases
llms.txt
GitHub
  • 简体中文
  • English
  • Getting started

    • Guide
    • Install and upgrade
    • Thirty seconds
  • Core concepts

    • Five hard rules
    • Bash 3.2 compatibility
    • Module map
    • POSIX subset
  • Common tasks

    • Cookbook
    • CLI framework
    • Machine-readable output
    • Security boundaries
    • Internationalisation
    • Testing and gates
    • Working with AI
  • Going further

    • Example projects
    • Man pages
    • Migration guide
    • Compatibility policy
    • Releasing
    • Contributing
    • Changelog
  • Troubleshooting

    • Troubleshooting
    • FAQ

Module map

lib/bootstrap.sh is the single entry point. It loads all 27 modules once, in topological order. You do not pick and choose what to source, and you should not copy one module's implementation into your own script -- that is just another way of hitting the same trap twice.

27 modules in five layers: foundations, files and system, process and version, integration, interaction and framework. Dependencies only point upward
27 modules in five layers: foundations, files and system, process and version, integration, interaction and framework. Dependencies only point upward

The table

ModuleResponsibilityKey functions
errorfailure and preconditionsdie fail require_cmd require_root require_file require_bash
i18ntranslation lookup_t _tn
logeverything to stderrlog_info log_ok log_warn log_error log_debug log_section
strstring ops 3.2 lacksstr_trim str_lower str_upper str_contains str_starts_with str_ends_with str_repeat
validateinput validationvalidate_not_empty validate_single_line validate_key validate_port validate_ip validate_version validate_abs_path validate_url validate_enum
fsatomic writes, idempotent editsfs_atomic_write fs_backup fs_ensure_dir fs_ensure_line fs_ensure_block fs_ensure_symlink fs_tmp_init
osthe only place for platform differencesos_name os_arch os_is_root os_has_cmd os_pkg_install os_sed_i os_md5 os_sha256
svcservice management (systemd verbs)svc_start svc_stop svc_restart svc_is_active svc_is_enabled svc_install_unit
verversion comparison (pure bash, segmented)ver_cmp ver_gt ver_lt ver_eq
statusmachine-readable status contractstatus_emit status_version status_extra status_is_machine status_state_valid
registrymanifest registryregistry_add registry_scan registry_get registry_list registry_deps registry_topo
profileprofile file primitivesprofile_write profile_append profile_parse profile_env
trapthe cleanup stacktrap_push trap_pop trap_cleanup trap_install trap_list
runrun a commandrun
retryretries with backoffretry
locksingle instancelock_acquire lock_release lock_held
netdownloads and readiness probesnet_download net_verify net_sha256 net_wait_port net_wait_http
httpsending HTTP requestsnet_request net_json net_escape_json
configKEY=VALUE and dotenv configurationconf_init conf_get conf_get_any conf_has conf_set conf_unset conf_disable conf_keys conf_load_dotenv conf_source
scaffoldtemplate variables, manifests, hooksscaffold_vars_set scaffold_vars_get scaffold_config_load scaffold_render scaffold_manifest_read scaffold_run_hook
promptinteractionask ask_yn ask_choice confirm
cliregistered-command frameworkcli_group cli_cmd cli_run cli_opt cli_opts cli_has cli_usage_global
manman page generationman_page man_module_page man_write_all man_modules man_count_functions
vendorwhere the library copy livesvendor_dir vendor_dir_rel vendor_dir_source vendor_dir_detect
procprocess groups and watchdogproc_start proc_stop proc_is_running proc_watchdog
gitthe right way to do gitgit_default_branch git_is_dirty git_tag git_fetch git_fast_forward git_reset_hard git_worktree_add

Load order is not alphabetical

Topological order exists because later modules call earlier ones. log needs _t (so i18n loads first), error needs log_error, and cli needs both log_error and _t.

That order lives in one file -- lib/modules.txt, with two columns:

i18n
log          i18n
error        i18n log
str          error

The first column is the module name, the second lists its direct dependencies (space separated, optional). lib/bootstrap.sh loads from it, tools/shdoc.sh generates the API reference from it, the site syncs from it -- adding a module means editing one file, with no second place to forget.

Dependencies must come first. Getting the order wrong does not have to wait for runtime to surface: make module-order-check names the offending call directly.

Load only what you need

By default everything loads (27 modules). To slim it down:

SHELLKIT_MODULES="log fs" . ./vendor/shellkit/lib/bootstrap.sh

Only the listed modules are loaded, and their transitive dependencies come along automatically (i18n is always loaded, because every module needs translations).

Pick a module by task

What you are doing nowWhat to use
emit a log linelog_info / log_ok / log_warn / log_error / log_debug / log_section
fail with an exit codedie / fail / require_cmd / require_root / require_file
read configuration (environment wins)conf_init then conf_get_any
change configuration idempotentlyconf_set; for any file, fs_ensure_line / fs_ensure_block
write a file without corrupting itfs_atomic_write; back up with fs_backup
download and verifynet_download URL DEST [SHA256]; mirror fallback is built in
wait for a port / for HTTPnet_wait_port / net_wait_http
run a command, stop on failurerun systemctl restart nginx
run a command, judge success yourselfrun --no-die systemctl is-active nginx
retry a few timesretry 5 curl -fsS "$url" -o x
guarantee a single instancelock_acquire deploy 30
always clean up on exittrap_push 'rm -rf "$workdir"' + trap_install
ask the user somethingask / ask_yn / ask_choice / confirm
add a subcommandregister with cli_cmd, implement cmd_<name>
output in several languages_t 'english msgid', translations in locale/

Boundaries that are easy to get wrong

  • run dies on failure by default, and the exit inside die ignores the caller's if / ||. To test success inside a condition, use run --no-die, which only returns the exit code.
  • retry does not retry usage errors (SK_USAGE) or verification failures (SK_VERIFY). Retrying those a hundred times gives the same answer.
  • lock_acquire pushes the release onto the cleanup stack as soon as it takes the lock, so you never write trap 'lock_release' by hand.
  • conf_get reads the config file only; conf_get_any is the environment-first one. The names differ slightly, the behaviour differs a lot.
Last updated: 11/22/26, 7:50 PM
Prev
Bash 3.2 compatibility
Next
POSIX subset
给 AI 直读:llms.txt 一个文件读完整个站点的地图