AGENTS.bash.md v0.0.1
This document provides guidelines for writing and testing Bash scripts in this repository.
Related documents:
The scripting guidelines are heavily based on the Bash Style Guide by Dave Eddy, which should be considered the primary reference for style.
#!/usr/bin/env bash for portability.Error Checking: Always check for potential errors, especially for commands that can fail, like cd.
# wrong
cd /some/path
rm file
# right
cd /some/path || exit 1
rm file
set -e: Do not use set -e. Handle errors explicitly."$var") to prevent word-splitting and globbing issues.local for all variables inside functions.[[ ... ]] for conditional testing.$(...) for command substitution, not backticks.For a comprehensive guide, refer to the Bash Style Guide.
This project uses BATS for testing. Tests are located in the tests/ directory and have a .bats extension.
bats tests/.bats tests/my_test.bats.Test Structure:
#!/usr/bin/env bats
@test "description of the test" {
run my_script "some argument"
[ "$status" -eq 0 ]
[ "$output" = "expected output" ]
}
$status, $output, $lines.For full documentation, see the BATS project on GitHub.