Overview
Thestring module provides comprehensive string manipulation utilities in pure Bash. All functions avoid external tools where possible, making them fast and portable.
Total functions: 130+
Inspection
Functions for checking string properties and contents.string::length
string::length
str- The string to measure
string::is_empty
string::is_empty
string::is_not_empty
string::is_not_empty
string::contains
string::contains
haystack- The string to search inneedle- The substring to find
string::starts_with
string::starts_with
str- The string to checkprefix- The prefix to match
string::ends_with
string::ends_with
str- The string to checksuffix- The suffix to match
string::matches
string::matches
str- The string to testregex- Bash-compatible regex pattern
Validation functions
string::is_integer
string::is_integer
string::is_float
string::is_float
string::is_hex
string::is_hex
0x prefix).string::is_bin
string::is_bin
0b prefix required).string::is_octal
string::is_octal
0 required).string::is_numeric
string::is_numeric
string::is_alnum
string::is_alnum
string::is_alpha
string::is_alpha
Case conversion
Functions for changing string case.string::upper
string::upper
string::upper::legacy for Bash 3 compatibility (uses tr)string::lower
string::lower
string::lower::legacy for Bash 3 compatibilitystring::capitalise
string::capitalise
string::capitalise::legacy for Bash 3 compatibilitystring::title
string::title
awkNaming convention conversion
Convert between different naming conventions: plain, snake_case, kebab-case, camelCase, PascalCase, CONSTANT_CASE, dot.case, and path/case.From plain (space-separated)
string::plain_to_snake
string::plain_to_snake
string::plain_to_kebab
string::plain_to_kebab
string::plain_to_camel
string::plain_to_camel
string::plain_to_pascal
string::plain_to_pascal
string::plain_to_constant
string::plain_to_constant
string::plain_to_dot
string::plain_to_dot
string::plain_to_path
string::plain_to_path
From snake_case
string::snake_to_plain
string::snake_to_plain
string::snake_to_kebab
string::snake_to_kebab
string::snake_to_camel
string::snake_to_camel
string::snake_to_pascal
string::snake_to_pascal
string::snake_to_constant
string::snake_to_constant
string::snake_to_dot
string::snake_to_dot
string::snake_to_path
string::snake_to_path
From kebab-case
string::kebab_to_plain
string::kebab_to_plain
hello-world → hello worldstring::kebab_to_snake
string::kebab_to_snake
hello-world → hello_worldstring::kebab_to_camel
string::kebab_to_camel
hello-world → helloWorldstring::kebab_to_pascal
string::kebab_to_pascal
hello-world → HelloWorldstring::kebab_to_constant
string::kebab_to_constant
hello-world → HELLO_WORLDstring::kebab_to_dot
string::kebab_to_dot
hello-world → hello.worldstring::kebab_to_path
string::kebab_to_path
hello-world → hello/worldFrom camelCase
string::camel_to_plain
string::camel_to_plain
helloWorld → hello worldstring::camel_to_snake
string::camel_to_snake
helloWorld → hello_worldstring::camel_to_kebab
string::camel_to_kebab
helloWorld → hello-worldstring::camel_to_pascal
string::camel_to_pascal
helloWorld → HelloWorldstring::camel_to_constant
string::camel_to_constant
helloWorld → HELLO_WORLDstring::camel_to_dot
string::camel_to_dot
helloWorld → hello.worldstring::camel_to_path
string::camel_to_path
helloWorld → hello/worldFrom PascalCase
string::pascal_to_plain
string::pascal_to_plain
HelloWorld → hello worldstring::pascal_to_snake
string::pascal_to_snake
HelloWorld → hello_worldstring::pascal_to_kebab
string::pascal_to_kebab
HelloWorld → hello-worldstring::pascal_to_camel
string::pascal_to_camel
HelloWorld → helloWorldstring::pascal_to_constant
string::pascal_to_constant
HelloWorld → HELLO_WORLDstring::pascal_to_dot
string::pascal_to_dot
HelloWorld → hello.worldstring::pascal_to_path
string::pascal_to_path
HelloWorld → hello/worldFrom CONSTANT_CASE
string::constant_to_plain
string::constant_to_plain
HELLO_WORLD → hello worldstring::constant_to_snake
string::constant_to_snake
HELLO_WORLD → hello_worldstring::constant_to_kebab
string::constant_to_kebab
HELLO_WORLD → hello-worldstring::constant_to_camel
string::constant_to_camel
HELLO_WORLD → helloWorldstring::constant_to_pascal
string::constant_to_pascal
HELLO_WORLD → HelloWorldstring::constant_to_dot
string::constant_to_dot
HELLO_WORLD → hello.worldstring::constant_to_path
string::constant_to_path
HELLO_WORLD → hello/worldFrom dot.case
string::dot_to_plain
string::dot_to_plain
hello.world → hello worldstring::dot_to_snake
string::dot_to_snake
hello.world → hello_worldstring::dot_to_kebab
string::dot_to_kebab
hello.world → hello-worldstring::dot_to_camel
string::dot_to_camel
hello.world → helloWorldstring::dot_to_pascal
string::dot_to_pascal
hello.world → HelloWorldstring::dot_to_constant
string::dot_to_constant
hello.world → HELLO_WORLDstring::dot_to_path
string::dot_to_path
hello.world → hello/worldFrom path/case
string::path_to_plain
string::path_to_plain
hello/world → hello worldstring::path_to_snake
string::path_to_snake
hello/world → hello_worldstring::path_to_kebab
string::path_to_kebab
hello/world → hello-worldstring::path_to_camel
string::path_to_camel
hello/world → helloWorldstring::path_to_pascal
string::path_to_pascal
hello/world → HelloWorldstring::path_to_constant
string::path_to_constant
hello/world → HELLO_WORLDstring::path_to_dot
string::path_to_dot
hello/world → hello.worldTrimming and whitespace
Functions for removing or normalizing whitespace.string::trim_left
string::trim_left
string::trim_right
string::trim_right
string::trim
string::trim
string::collapse_spaces
string::collapse_spaces
trstring::strip_spaces
string::strip_spaces
Substrings
Functions for extracting parts of strings.string::substr
string::substr
str- Source stringstart- Starting position (0-indexed)length- Optional length to extract
string::index_of
string::index_of
string::before
string::before
string::after
string::after
string::before_last
string::before_last
string::after_last
string::after_last
Manipulation
Functions for modifying strings.string::replace
string::replace
string::replace_all
string::replace_all
string::remove
string::remove
string::remove_first
string::remove_first
string::reverse
string::reverse
rev (falls back to awk)string::repeat
string::repeat
string::pad_left
string::pad_left
str- String to padwidth- Target widthchar- Padding character (default: space)
string::pad_right
string::pad_right
string::pad_center
string::pad_center
string::truncate
string::truncate
str- String to truncatemax- Maximum length (including suffix)
- Uses
...for lengths > 5 - Uses
…(single ellipsis) for shorter lengths - Intelligently handles very small max values
Splitting and joining
string::split
string::split
string::join
string::join
delimiter- String to insert between elementsargs...- Elements to join
Encoding and hashing
URL encoding
string::url_encode
string::url_encode
string::url_decode
string::url_decode
Base64 encoding
string::base64_encode
string::base64_encode
base64 command).string::base64_decode
string::base64_decode
string::base64_encode::pure
string::base64_encode::pure
string::base64_decode::pure
string::base64_decode::pure
Base32 encoding
string::base32_encode
string::base32_encode
base32 or gbase32 (GNU coreutils)string::base32_decode
string::base32_decode
base32 or gbase32string::base32_encode::pure
string::base32_encode::pure
string::base32_decode::pure
string::base32_decode::pure
Cryptographic hashes
string::md5
string::md5
md5sum (Linux) or md5 (macOS)string::sha256
string::sha256
sha256sum (Linux) or shasum (macOS)Generation
Functions for generating random strings and identifiers.string::random
string::random
length- Length of string to generate (default: 16)
/dev/urandomstring::uuid
string::uuid
uuidgen or /proc/sys/kernel/random/uuid (falls back to manual construction)