A Function Without local Overwrote My Variable and rm -rf Deleted the Wrong Directory
📰 Dev.to · Anguishe
Learn how a function without local overwrote a variable and caused a catastrophic rm -rf command to delete the wrong directory, and how to avoid similar mistakes in your own code
Action Steps
- Use the local keyword when assigning variables in functions to avoid overwriting global variables
- Test your scripts thoroughly in a controlled environment before deploying to production
- Use absolute paths instead of relative paths to avoid directory traversal issues
- Implement safeguards such as prompting for confirmation before executing destructive commands like rm -rf
- Regularly review and refactor your code to catch potential issues before they cause problems
Who Needs to Know This
Developers and DevOps engineers can benefit from this lesson to improve their scripting and deployment practices, and avoid similar disasters
Key Insight
💡 Using local variables and testing scripts thoroughly can prevent disastrous mistakes
Share This
💡 Beware of functions without local overwriting variables and causing catastrophic consequences! 🚨
Key Takeaways
Learn how a function without local overwrote a variable and caused a catastrophic rm -rf command to delete the wrong directory, and how to avoid similar mistakes in your own code
Full Article
The deploy script had been running in production for four months without a problem. It built releases...
DeepCamp AI