{
  "title": "Shell Scripting को समझना: उन्नत तकनीकें और सर्वोत्तम प्रथाएं",
  "excerpt": "Shell scripting की बुनियादी बातों पर आगे बढ़ते हुए, यह गाइड उन्नत तकनीकों और सर्वोत्तम प्रथाओं में गहराई से उतरती है जो आपके scripting कौशल को उन्नत करेंगी। हम error handling, command substitution, process management का पता लगाएंगे, और कुशल, मजबूत और maintainable scripts लिखने के लिए मूल्यवान सुझाव साझा करेंगे। इन उन्नत अवधारणाओं में महारत हासिल करके, आप जटिल scripting चुनौतियों से निपटने और shell scripting की पूर्ण शक्ति का उपयोग करने के लिए अच्छी तरह से सुसज्जित होंगे।",
  "content_html": "<p>मेरी पिछली blog posts में, हमने shell का उपयोग करने की मूल बातें शामिल कीं और शुरुआती लोगों के लिए shell scripting का परिचय दिया। अब जब आपके पास shell scripting में एक मजबूत आधार है, तो यह कुछ उन्नत तकनीकों और सर्वोत्तम प्रथाओं का पता लगाने का समय है जो आपको अधिक कुशल, मजबूत और maintainable scripts लिखने में मदद करेंगी। इस blog post में, हम error handling, command substitution, process management, और shell scripts लिखने के लिए सर्वोत्तम प्रथाओं पर चर्चा करेंगे। हम आगे सीखने के लिए कुछ संसाधन भी प्रदान करेंगे।</p>\n\n<h2>Error Handling</h2>\n\n<p>Error handling मजबूत shell scripts लिखने का एक आवश्यक पहलू है। डिफ़ॉल्ट रूप से, shell scripts बाद की commands को निष्पादित करना जारी रखती हैं भले ही कोई error हो। इस व्यवहार को बदलने के लिए और यदि कोई command विफल होती है तो अपनी script को तुरंत exit करने के लिए, आप <code>set -e</code> option का उपयोग कर सकते हैं:</p>\n\n<pre><code class=\"language-bash\">#!/bin/bash\nset -e\n\n# Your script here\n</code></pre>\n\n<p>आप कस्टम error handling व्यवहार को परिभाषित करने के लिए <code>trap</code> command का भी उपयोग कर सकते हैं। उदाहरण के लिए, आप एक cleanup function बना सकते हैं जिसे आपकी script के अप्रत्याशित रूप से exit होने पर call किया जाएगा:</p>\n\n<pre><code class=\"language-bash\">#!/bin/bash\n\nfunction cleanup() {\n  echo \"Cleaning up before exiting...\"\n  # Your cleanup code here\n}\n\ntrap cleanup EXIT\n\n# Your script here\n</code></pre>\n\n<h2>Command Substitution</h2>\n\n<p>Command substitution आपको किसी command के output को capture करने और इसे एक variable में store करने की अनुमति देता है। यह आपकी script के भीतर किसी command के output को process करने के लिए उपयोगी हो सकता है। Command substitution करने के दो तरीके हैं:</p>\n\n<p>1. Backticks (` `) का उपयोग करना:</p>\n\n<pre><code class=\"language-bash\">output=`ls`\n</code></pre>\n\n<p>2. <code>$()</code> का उपयोग करना:</p>\n\n<pre><code class=\"language-bash\">output=$(ls)\n</code></pre>\n\n<p><code>$()</code> syntax को प्राथमिकता दी जाती है क्योंकि यह अधिक readable है और आसानी से nested किया जा सकता है।</p>\n\n<h2>Process Management</h2>\n\n<p>Shell scripts को अक्सर background processes को manage करने की आवश्यकता होती है, जैसे कि उन्हें start करना, stop करना या monitor करना। Process management के लिए कुछ उपयोगी commands यहां दी गई हैं:</p>\n\n<ul>\n<li><code>&amp;</code>: Command के अंत में ampersand (<code>&amp;</code>) जोड़कर किसी command को background में चलाएं।</li>\n</ul>\n\n<pre><code class=\"language-bash\">long_running_command &amp;\n</code></pre>\n\n<ul>\n<li><code>wait</code>: Script के साथ जारी रखने से पहले background process के पूरा होने की प्रतीक्षा करें।</li>\n</ul>\n\n<pre><code class=\"language-bash\">long_running_command &amp;\nwait\n</code></pre>\n\n<ul>\n<li><code>kill</code>: किसी process को एक signal भेजकर समाप्त करें।</li>\n</ul>\n\n<pre><code class=\"language-bash\">kill -9 process_id\n</code></pre>\n\n<ul>\n<li><code>ps</code>: चल रही processes और उनकी process IDs की सूची बनाएं।</li>\n</ul>\n\n<pre><code class=\"language-bash\">ps aux\n</code></pre>\n\n<h2>Best Practices</h2>\n\n<p>Shell scripts लिखने के लिए कुछ सर्वोत्तम प्रथाएं यहां दी गई हैं:</p>\n\n<ul>\n<li>सार्थक variable और function नामों का उपयोग करें।</li>\n<li>जटिल या गैर-स्पष्ट code को समझाने के लिए comments जोड़ें।</li>\n<li>Readability में सुधार के लिए indentation और whitespace का उपयोग करें।</li>\n<li>अपनी scripts को छोटे functions में तोड़कर modular रखें।</li>\n<li>Functions के भीतर variables के scope को सीमित करने के लिए <code>local</code> keyword का उपयोग करें।</li>\n<li>Spaces और special characters के साथ समस्याओं को रोकने के लिए हमेशा अपने variables को quote करें।</li>\n<li>Conditional expressions के लिए <code>[[ ]]</code> syntax का उपयोग करें, क्योंकि यह <code>[ ]</code> की तुलना में अधिक मजबूत है।</li>\n</ul>\n\n<h2>Resources</h2>\n\n<p>अपने shell scripting कौशल को और बेहतर बनाने के लिए, यहां कुछ संसाधन दिए गए हैं:</p>\n\n<ul>\n<li><a href=\"https://google.github.io/styleguide/shellguide.html\">Google Shell Style Guide</a>: Shell scripts लिखने के लिए एक व्यापक style guide, जो Google द्वारा बनाई गई है।</li>\n<li><a href=\"https://www.shellcheck.net/\">ShellCheck</a>: Shell scripts के लिए एक static analysis tool जो आपको अपने code में संभावित समस्याओं की पहचान करने और उन्हें ठीक करने में मदद कर सकता है।</li>\n<li><a href=\"https://github.com/alebcay/awesome-shell\">Awesome Shell</a>: Shell scripting के लिए शानदार command-line frameworks, toolkits, guides और अन्य संसाधनों की एक curated list।</li>\n</ul>\n\n<p>निष्कर्ष में, shell scripting में उन्नत तकनीकों और सर्वोत्तम प्रथाओं में महारत हासिल करना आपको अधिक कुशल, मजबूत और maintainable scripts लिखने में मदद करेगा। Error handling, command substitution, process management को समझकर, और सर्वोत्तम प्रथाओं का पालन करके, आप एक shell scripting विशेषज्ञ बनने की राह पर अच्छी तरह से आगे बढ़ेंगे।</p>",
  "source_hash": "sha256:a4da7cd9877fba777249cd1c78b6ee3f60e6881ff6611165a59eaf0b5262baf9",
  "model": "claude-sonnet-4-5-20250929",
  "generated_at": "2026-01-02T00:09:29.041067+00:00"
}