Version: 0.1.1
Lightweight Bash validation helpers for common types, formats, and safe text. Designed for CLI scripts, CI/CD jobs, and automation where quick input checks save time and prevent mistakes.
- Type and format checks (integers, UUID, IP, IPv4 CIDR, Base64, date format)
- Safe text validation to reduce shell injection risk
- Small, dependency-free, easy to source
- Clear return codes:
0pass,1fail
I use this library in my own projects and decided to share these small helpers with the community. This is my first public library, so feedback and suggestions are welcome.
Clone or copy bashinator.sh into your project.
source "./bashinator.sh"
if ! IsInteger "$PORT"; then
printf '%s\n' "PORT must be an integer" >&2
exit 1
fiEach function returns a status code: 0 means valid, 1 means invalid.
| Function | Input | Output | Meaning |
|---|---|---|---|
IsEmpty value |
string | status | 0 if empty |
IsNull value |
string | status | 0 if value is null |
IsBoolean value |
string | status | 0 if true/false |
IsString value |
string | status | 0 if contains letters |
IsInteger value |
string | status | 0 if signed integer |
IsPositiveInteger value |
string | status | 0 if integer > 0 |
IsGreaterZero value |
string | status | 0 if integer >= 0 |
IsIPv4 value |
string | status | 0 if valid IPv4 |
IsIPv6 value |
string | status | 0 if IPv6 format |
IsIPv4CIDR value |
string | status | 0 if IPv4 CIDR format |
IsUUID value |
string | status | 0 if UUID 8-4-4-4-12 |
IsBase64 value |
string | status | 0 if Base64 chars/padding |
IsDate value |
string | status | 0 if YYYY-MM-DD format |
IsEnum value values... |
value + list | status | 0 if match found |
ContainsDangerousChars text |
string | status | 0 if dangerous chars |
IsSafeText text [max_len] |
string + max | status | 0 if safe |
IsEmptyOrWhitespace text |
string | status | 0 if whitespace only |
IsValueInArray value array_name |
value + array | status | 0 if found |
WhatIs value |
string | stdout | prints type name |
source "./bashinator.sh"
if IsEmpty "$API_TOKEN"; then
printf '%s\n' "API_TOKEN is required" >&2
exit 1
fi
if ! IsPositiveInteger "$RETRIES"; then
RETRIES=3
fiif ContainsDangerousChars "$user_input"; then
printf '%s\n' "Unsafe characters in input" >&2
exit 1
ficase "$(WhatIs "$value")" in
integer) timeout="$value" ;;
ipv4) target_ip="$value" ;;
*) printf '%s\n' "Unknown input type" >&2; exit 1 ;;
esac- English:
Doc/bashinator_doc_en.md - Russian:
Doc/bashinator_doc_ru.md
Contributions are welcome. Please follow these simple rules to keep the project consistent and easy to review:
- Open an issue or describe the change in the PR (what/why).
- Keep changes focused and small; avoid mixing refactors with new features.
- Add or update docs when behavior changes.
- Prefer tests or reproducible examples for bug fixes.
- Run formatting and
shellcheckif you use it locally.
Based on the current code style and common Bash repos:
- Use
UpperCamelCasefor function names, andlocalfor variables. - Prefer early returns for validation checks.
- Keep functions small and single-purpose.
- Use
[[ ... ]]for regex and string tests; quote variables in tests. - Always return
0for success and1for validation failure. - Avoid external dependencies unless absolutely necessary.
IsDatevalidates format only (YYYY-MM-DD), not calendar correctness.IsIPv6andIsIPv4CIDRare basic format checks, not deep validation.IsIPv4CIDRvalidates masks0..32without leading zeros.IsBase64checks allowed characters and padding only.IsIntegeraccepts signed integers but not+sign or dots.
MIT