Linux Basic — Naming Conventions
Naming Conventions
Consistent naming makes scripts self-documenting. The Bash community has loose conventions; this page gives you a practical subset.
Variables
| Type | Convention | Example |
|---|---|---|
| Local / script variables | lowercase_snake_case |
user_count, input_file |
| Constants (readonly) | UPPER_CASE |
MAX_RETRIES, DEFAULT_PORT |
| Environment variables | UPPER_CASE |
PATH, HOME, MYAPP_CONFIG |
| Loop counters | i, j, k (sparingly) |
for i in ... |
readonly MAX_RETRIES=3
user_count=0
input_file="data.txt"
Avoid single-letter names except for loop counters in short, obvious loops.
Functions
lowercase_with_underscores, verb-first:
get_user_count() { ... }
validate_input() { ... }
send_alert() { ... }
Private/helper functions can start with _:
_parse_config() { ... }
Files & Scripts
kebab-case or snake_case for script names:
backup-database.sh
log_cleanup.sh
Avoid spaces, capitals, and special chars. Use .sh suffix for scripts.
Descriptive Over Clever
| Bad | Good |
|---|---|
uc |
user_count |
f |
input_file |
tmp |
temp_output_file |
x |
threshold |
Disk space is cheap. Ambiguity is expensive.
Constants at the Top
Declare all readonly constants in one block near the top of the script:
readonly MAX_RETRIES=3
readonly TIMEOUT_SECONDS=30
readonly LOG_DIR="/var/log/myapp"
This acts as a configuration section.
Next → Commenting Best Practices