Skip to main content

Source the framework

After compiling the framework, source it in your script:
source /path/to/compiled.sh

# Now all functions are available
string::upper "hello world"  # HELLO WORLD

Relative path sourcing

For scripts that live next to the compiled framework:
#!/usr/bin/env bash
source "$(dirname "$0")/compiled.sh"

# Your script here
Sourcing the framework makes all ~785 functions immediately available in your script’s namespace.

Common usage patterns

Here are practical examples using real functions from bash::framehead:

String manipulation

# Convert to uppercase
string::upper "hello world"  # HELLO WORLD

# Convert to lowercase
string::lower "HELLO WORLD"  # hello world

# Capitalize first letter
string::capitalise "hello"  # Hello

# Title case
string::title "hello world"  # Hello World

Math operations

# Factorial
math::factorial 10  # 3628800

# Fibonacci
math::fibonacci 7  # 13

# Power
math::pow 2 3  # 8

# GCD and LCM
math::gcd 12 18  # 6
math::lcm 4 6    # 12

Array operations

# Get array properties
array::length a b c           # 3
array::first a b c            # a
array::last a b c             # c
array::get 1 a b c            # b

# Check if array contains element
array::contains b a b c && echo "found"

# Find index of element
array::index_of b a b c       # 1

Filesystem operations

# Check if file/directory exists
fs::exists ./myfile && echo "found"
fs::is_file ./myfile && echo "is a file"
fs::is_dir ./mydir && echo "is a directory"

# Get file properties
fs::size ./myfile              # Size in bytes
fs::size::human ./myfile       # Human-readable size
fs::permissions ./myfile       # Octal permissions
fs::owner ./myfile             # Owner username

# Path operations
fs::path::basename /foo/bar/test.txt  # test.txt
fs::path::dirname /foo/bar/test.txt   # /foo/bar
fs::path::extension file.txt          # txt
fs::path::stem file.txt               # file

Time and date

# Format duration in seconds
timedate::duration::format 3661  # 1h 1m 1s

# Get current timestamp
timedate::timestamp              # Unix timestamp

# Date arithmetic and formatting
timedate::now                    # Current date/time
timedate::format "%Y-%m-%d"      # Formatted date

Runtime detection

# Detect operating system and architecture
runtime::os            # linux, darwin, etc.
runtime::arch          # x86_64, arm64, etc.
runtime::distro        # ubuntu, debian, fedora, etc.

# Check Bash version
runtime::bash_version         # Full version
runtime::bash_version::major  # Major version number
runtime::is_minimum_bash 5 && echo "Bash 5+"

# Check for commands
runtime::has_command curl && echo "curl available"
runtime::has_command bc && echo "bc available"

# Environment checks
runtime::is_root && echo "running as root"
runtime::is_ssh && echo "SSH session"
runtime::is_ci && echo "CI environment"

Hash functions

# Cryptographic hashes
hash::md5 "hello"       # MD5 hash
hash::sha256 "hello"    # SHA-256 hash
hash::sha512 "hello"    # SHA-512 hash

# Fast non-cryptographic hashes
hash::djb2 "hello"      # DJB2 hash
hash::fnv1a32 "hello"   # FNV-1a 32-bit
hash::crc32 "hello"     # CRC32

# Verify hash
hash::verify "hello" "$(hash::sha256 hello)" sha256 && echo "verified"

# Short hash (for file names, etc.)
hash::short "hello" 8   # 8-character hash

Complete example script

Here’s a practical script that demonstrates multiple modules working together:
#!/usr/bin/env bash
source "$(dirname "$0")/compiled.sh"

# Validate environment
if ! runtime::is_minimum_bash 4; then
  echo "Error: Bash 4.3+ required"
  exit 1
fi

# Process command line argument
input="${1:-hello world}"

# String operations
echo "Original: $input"
echo "Uppercase: $(string::upper "$input")"
echo "Reversed: $(string::reverse "$input")"
echo "Length: $(string::length "$input") characters"

# Convert to different naming conventions
if string::contains "$input" " "; then
  echo "Snake case: $(string::plain_to_snake "$input")"
  echo "Kebab case: $(string::plain_to_kebab "$input")"
  echo "Camel case: $(string::plain_to_camel "$input")"
fi

# Generate hash
echo "SHA-256: $(hash::sha256 "$input")"
echo "Short hash: $(hash::short "$input" 8)"

# Math example
if [[ "$input" =~ ^[0-9]+$ ]]; then
  echo "Factorial: $(math::factorial "$input")"
  math::is_prime "$input" && echo "$input is prime" || echo "$input is not prime"
fi

# System info
echo "Running on: $(runtime::os) $(runtime::arch)"
echo "Distribution: $(runtime::distro)"
echo "Bash version: $(runtime::bash_version)"

Next steps

1

Explore modules

Browse the module reference to discover all available functions
2

Read the wiki

Check the wiki/ directory in the repository for detailed documentation on each module
3

Run tests

Study the test suite in main.sh for more usage examples
4

Customize your build

Remove modules you don’t need and recompile for a lighter footprint
Functions that require optional dependencies (like bc for floating point math or openssl for HMAC) will fail gracefully with helpful error messages if the dependency is missing.

Common tasks reference

TaskCommand
Compile framework./main.sh compile
Run tests./main.sh test ./compiled.sh
Get statistics./main.sh stat ./compiled.sh
Generate wiki./gen_wiki.sh ./compiled.sh ./wiki
Custom compilation./main.sh compile myname.sh

Module reference

Complete documentation for all 16 modules

GitHub repository

View source code and contribute

Build docs developers (and LLMs) love