Skillpedia
برمجة عامة41k · #6783

bash-defensive-patterns

ما الذي تفعله

يعلّم هذا الدليل كتابة سكربتات أتمتة (Bash) أكثر أمانا وموثوقية. يساعد على منع الأخطاء الشائعة ويضمن أن تعمل السكربتات بشكل صحيح حتى في الظروف غير المتوقعة.

متى تستخدمها

  • ✓عندما تكتب سكربتات لأتمتة مهام مهمة في العمل.
  • ✓عندما تبني خطوات أتمتة لعمليات التطوير (CI/CD).
  • ✓عندما تطور أدوات نظام يجب أن تكون موثوقة جدا.

رابط المهارة

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

انسخه والصقه في الذكاء الاصطناعي الذي تستخدمه (Claude أو ChatGPT أو Cursor) واطلب منه اتباع التعليمات.

طريقة الاستخدام

أسهل طريقة: انسخ الرسالة والصقها في الذكاء الاصطناعي الذي تستخدمه. سيقرأ المهارة وينفّذ تعليماتها.

رسالة جاهزة للصق

استخدم هذه المهارة لمساعدتي: https://github.com/wshobson/agents/blob/main/plugins/shell-scripting/skills/bash-defensive-patterns/SKILL.md اقرأ ملف SKILL.md في هذا الرابط ونفّذ تعليماته لمهمتي.
تريد أن يجد الذكاء الاصطناعي مهارات مثل هذه بنفسه؟ثبّت خادم Skillpedia MCP المجاني: سطر واحد، ويبحث في 15,000+ مهارة قبل كل مهمة.ثبّته في دقيقة واحدة →

مثال على ما تطلبه من الذكاء الاصطناعي

“كيف أكتب سكربت Bash لا يفشل إذا كان ملف غير موجود؟”

5 مهارات جديدة كل أسبوع. قراءة في دقيقة واحدة.

كيف تعمل

تستخدم تقنيات مثل تفعيل أوضاع الأمان، ومنها الأمر set -euo pipefail، وحماية المتغيرات دائما بعلامات الاقتباس المزدوجة، والتحقق من نجاح تنفيذ الأوامر.

المحتوى التقني (ملف 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، تجعل السكربت أكثر دقة، وتفرض تصحيح الأخطاء الشائعة التي قد تمر دون ملاحظة.

لماذا أضع المتغيرات بين علامتي اقتباس؟

وضع المتغيرات بين علامتي اقتباس يمنع السكربت من إساءة تفسير المسافات أو الرموز الخاصة داخل قيمة المتغير، فتتجنب الأخطاء.

ماذا تعني «عدم التأثير عند التكرار» (idempotency)؟

السكربت عديم التأثير عند التكرار يمكن تشغيله عدة مرات دون أن يسبب آثارا غير مقصودة. والنتيجة النهائية تكون نفسها مهما تكرر التشغيل.

التفاصيل

الوصف الأصلي من المؤلف

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

هل هذه المهارة مفيدة؟

0

سجّل الدخول للتصويت.

التعليقات

  • …

المزيد من المهارات من هذا المستودع

مهارات مشابهة