मुख्य सामग्री पर जाएँ
Skillpedia
सामान्य कोडिंग41k · #6783

bash-defensive-patterns

यह क्या करती है

यह गाइड सिखाती है कि सुरक्षित और भरोसेमंद automation scripts (Bash) कैसे लिखें। यह आम गलतियों को रोकने में मदद करती है और यह सुनिश्चित करती है कि आपकी scripts अनपेक्षित स्थितियों में भी सही तरीके से चलें।

कब इस्तेमाल करें

  • ✓काम के ज़रूरी कामों को automate करने के लिए scripts बनाते समय।
  • ✓development process (CI/CD) के automation steps बनाते समय।
  • ✓ऐसे system tools बनाते समय जो बहुत भरोसेमंद होने चाहिए।

Skill का लिंक

https://github.com/wshobson/agents/blob/main/plugins/shell-scripting/skills/bash-defensive-patterns/SKILL.md

इसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।

कैसे इस्तेमाल करें

सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।

पेस्ट करने के लिए तैयार मैसेज

इस skill से मेरी मदद करो: https://github.com/wshobson/agents/blob/main/plugins/shell-scripting/skills/bash-defensive-patterns/SKILL.md इस लिंक की SKILL.md फ़ाइल पढ़ो और मेरे काम में उसके निर्देशों का पालन करो।
क्या आप चाहते हैं कि आपका AI ऐसी skills खुद ढूँढे?मुफ़्त Skillpedia MCP इंस्टॉल करें: बस एक लाइन, और हर काम से पहले यह 15,000+ skills में खोजता है।1 मिनट में इंस्टॉल करें →

AI से क्या माँगें: उदाहरण

“Bash script कैसे लिखूँ ताकि file न होने पर वह फेल न हो?”

हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।

यह कैसे काम करती है

यह तकनीकें इस्तेमाल करता है जैसे safety modes चालू करना (`set -euo pipefail`), variables को हमेशा quotes में रखना (`"$variable"`), और जाँचना कि commands सफलतापूर्वक चले या नहीं।

तकनीकी सामग्री (मूल SKILL.md)

लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।

Bash Defensive Patterns

Comprehensive guidance for writing production-ready Bash scripts using defensive programming techniques, error handling, and safety best practices to prevent common pitfalls and ensure reliability.

When to Use This Skill

  • Writing production automation scripts
  • Building CI/CD pipeline scripts
  • Creating system administration utilities
  • Developing error-resilient deployment automation
  • Writing scripts that must handle edge cases safely
  • Building maintainable shell script libraries
  • Implementing comprehensive logging and monitoring
  • Creating scripts that must work across different platforms

Detailed patterns and worked examples

Detailed pattern documentation lives in references/details.md. Read that file when the navigation tier above is insufficient.

Best Practices Summary

  1. Always use strict mode - set -Eeuo pipefail
  2. Quote all variables - "$variable" prevents word splitting
  3. Use [[]] conditionals - More robust than [ ]
  4. Implement error trapping - Catch and handle errors gracefully
  5. Validate all inputs - Check file existence, permissions, formats
  6. Use functions for reusability - Prefix with meaningful names
  7. Implement structured logging - Include timestamps and levels
  8. Support dry-run mode - Allow users to preview changes
  9. Handle temporary files safely - Use mktemp, cleanup with trap
  10. Design for idempotency - Scripts should be safe to rerun
  11. Document requirements - List dependencies and minimum versions
  12. Test error paths - Ensure error handling works correctly
  13. Use command -v - Safer than which for checking executables
  14. Prefer printf over echo - More predictable across systems
अक्सर पूछे जाने वाले सवाल

'strict mode' क्या है?

यह नियमों का एक सेट है (`set -Eeuo pipefail`) जो script को ज़्यादा सख्त बनाता है और आम गलतियों को, जो वरना नज़र न आतीं, ठीक करने पर मजबूर करता है।

variables को quotes में क्यों रखना चाहिए?

variable के चारों ओर quotes (`"$variable"`) लगाने से script variable की value में मौजूद spaces या खास अक्षरों को गलत नहीं समझती, इसलिए errors से बचाव होता है।

'idempotency' का मतलब क्या है?

idempotent script को कई बार चलाया जा सकता है बिना किसी अनचाहे असर के। इसका मतलब है कि script कितनी भी बार चले, अंतिम परिणाम एक जैसा रहता है।

जानकारी

लेखक का मूल विवरण

Master defensive Bash programming techniques for production-grade scripts. Use when writing robust shell scripts, CI/CD pipelines, or system utilities requiring fault tolerance and safety.

repo: wshobson/agents

लोकप्रियता

GitHub स्टार
41k
रैंकिंग में स्थान
#6783
लाइसेंस
MIT
अपडेट की गई
15/10/2026

क्या यह skill काम की है?

0

लॉग इन करें वोट करने के लिए।

कमेंट

  • …

इस repository की और skills

मिलती-जुलती skills