❌ Top 10 Common Mistakes in Writing Scripts
1. Hardcoding Values
- Using fixed paths, IPs, or credentials inside the script.
- ✅ Use variables or config files instead.
2. Missing Input Validation
- Assuming user input or arguments are always correct.
- ✅ Always check for type, format, and range.
3. No Error Handling
- Ignoring exceptions or command failures.
- ✅ Use
try/catch
,if [ $? -ne 0 ]
, or similar.
4. Not Cleaning Up Temporary Files
- Leaving behind unused logs, temp data, or cache.
- ✅ Add cleanup functions or use
trap
in shell scripts.
5. Not Checking Command Return Codes
- Continuing the script even when a step fails.
- ✅ Always check exit codes before moving forward.
6. Poor Naming Conventions
- Using vague variable or function names (
x
,temp
,data1
). - ✅ Use descriptive and consistent naming.
7. Infinite or Uncontrolled Loops
- Forgetting loop conditions or exit criteria.
- ✅ Always define clear limits and break conditions.
8. Lack of Documentation
- No comments, no usage instructions.
- ✅ Add inline comments and a help section (
--help
flag).
9. Storing Passwords in Plaintext
- Writing credentials directly in the code.
- ✅ Use environment variables or secure vaults.
10. Not Testing Before Deployment
- Running scripts directly in production without testing.
- ✅ Always test in a sandbox or staging environment first.
Top comments (0)