CLI Tools bash Intermediate New

Dotenv File Linter

Check .env files for common mistakes: duplicate keys, missing values, invalid characters.

bash
#!/bin/bash
FILE=${1:-.env}
errors=0

while IFS= read -r line; do
  [[ -z "$line" || "$line" =~ ^# ]] && continue
  if ! echo "$line" | grep -qP "^[A-Z0-9_]+="; then
    echo "BAD KEY: $line"; ((errors++))
  fi
  key=$(echo "$line" | cut -d= -f1)
  val=$(echo "$line" | cut -d= -f2-)
  if [ -z "$val" ]; then
    echo "EMPTY VALUE: $key"; ((errors++))
  fi
done < "$FILE"

echo "$errors error(s) found in $FILE"
exit $errors

Prerequisites

  • bash

Pro Tips

  • → Run in pre-commit hook to catch issues before code review.

Was this module useful?

Share your experience — it helps the team improve.

Leave Feedback

Commercial Licensing

Acquire a production access token or template license for enterprise deployment.

Module Info

Language
bash
Level
Intermediate
Read time
2 min
Published
Aug 2026
License
Commercial License

Newsletter

New modules every week, directly to your inbox.