with one click
bash
Write Bash scripts following best practices. Use when creating shell scripts, automation, or CLI tools. Covers safe scripting patterns.
Menu
Write Bash scripts following best practices. Use when creating shell scripts, automation, or CLI tools. Covers safe scripting patterns.
Based on SOC occupation classification
| name | bash |
| description | Write Bash scripts following best practices. Use when creating shell scripts, automation, or CLI tools. Covers safe scripting patterns. |
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
# Script description
# Usage: ./script.sh <arg1> <arg2>
readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
main() {
local arg1="${1:-default}"
# Script logic here
echo "Running with: $arg1"
}
main "$@"
set -e # Exit on error
set -u # Error on undefined variables
set -o pipefail # Catch pipe failures
set -x # Debug: print commands
# Declaration
readonly CONST="immutable"
local var="function scoped"
# Default values
name="${1:-default}" # Use default if unset
name="${1:?Error: missing}" # Error if unset
# String operations
"${var^^}" # Uppercase
"${var,,}" # Lowercase
"${var#prefix}" # Remove prefix
"${var%suffix}" # Remove suffix
# File tests
[[ -f "$file" ]] # Is file
[[ -d "$dir" ]] # Is directory
[[ -r "$file" ]] # Is readable
[[ -x "$file" ]] # Is executable
# String tests
[[ -z "$var" ]] # Is empty
[[ -n "$var" ]] # Is not empty
[[ "$a" == "$b" ]] # Equals
# Numeric tests
(( num > 5 )) # Greater than
(( num == 5 )) # Equals
log() {
local level="$1"
local message="$2"
echo "[$(date +'%Y-%m-%d %H:%M:%S')] [$level] $message" >&2
}
die() {
log "ERROR" "$1"
exit 1
}
require_command() {
command -v "$1" >/dev/null 2>&1 || die "Required command not found: $1"
}
# Trap for cleanup
cleanup() {
rm -rf "$TMP_DIR"
}
trap cleanup EXIT
# Catch errors
if ! result=$(some_command 2>&1); then
die "Command failed: $result"
fi
# For loop
for item in "${array[@]}"; do
echo "$item"
done
# While read
while IFS= read -r line; do
echo "$line"
done < file.txt
# Process substitution
while read -r line; do
echo "$line"
done < <(command)
"$var"[[ instead of [local in functionsreadonly for constantsset -euo pipefailBiome 2.x linting and formatting patterns. Use when configuring code quality tools, setting up linting rules, formatting code, or integrating with CI/CD. Covers migration from ESLint/Prettier.
Hono 4.x web framework patterns. Use when building APIs, middleware, routing, or server-side applications. Covers multi-runtime support (Node, Bun, Cloudflare Workers), validation, CORS, and error handling.
Radix UI primitive patterns. Use when building accessible, unstyled UI components like dialogs, dropdowns, tooltips, tabs, and selects. Covers Tailwind styling, keyboard navigation, animations, and portal management.
React development patterns. Use when building React components, managing state, creating custom hooks, or optimizing React applications. Covers React 19 features, TypeScript integration, and composition patterns.
Tailwind CSS 4.x utility-first styling patterns. Use when building UI components, creating responsive layouts, implementing design systems, or customizing themes. Covers CSS-first configuration, @theme directive, and component patterns.
Vite 7.x build tool patterns. Use when configuring build setup, development server, environment variables, asset handling, or optimizing production builds for React applications.