मुख्य सामग्री पर जाएँ
kitlocal.dev

Bash चीटशीट

लोकल चलता है

100% आपके ब्राउज़र में प्रोसेस होता है। इनपुट और आउटपुट कभी आपके डिवाइस से बाहर नहीं जाते।

GNU Bash स्क्रिप्टिंग और इंटरैक्टिव शॉर्टकट: पैरामीटर एक्सपेंशन, ऐरे, लूप, कंडीशनल्स, रीडायरेक्शन और Bash 5.3 पर परखा गया जॉब कंट्रोल।

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

Bash parses a line in phases: expansions ($var, $(cmd), globs) happen before the command runs, and whitespace splits unquoted expansions into separate words. Double-quoting "$var" keeps spaces intact while still expanding variables; single quotes disable all expansion.

सर्वाइवल किट

वे कुछ कमांड जिन्हें सबसे पहले सीखना चाहिए।

41 कमांड

कीबोर्ड शॉर्टकट/खोज पर फ़ोकस करेंJKचयन आगे-पीछे करेंCचयनित कॉपी करेंFचयनित बुकमार्क करेंEscखोज साफ़ करें

Script safety & quoting

Start scripts with strict error checking and quote variable expansions to prevent silent failures.

आधिकारिक दस्तावेज़: The Set Builtin
  • आवश्यक

    Exit on errors, unset variables and failed pipeline commands.

    set -euo pipefail

    इसका उपयोग कब करें

    Prevents scripts from charging ahead after an earlier failure or blank variable expansion.

    घटक विवरण

    -e
    exit immediately when a command returns non-zero
    -u
    treat referencing an unset variable as an error
    -o pipefail
    fail a pipeline if any stage fails, not just the last

    उदाहरण

    Place `set -euo pipefail` at the top of scripts to fail fast with exit code 1.

    bash -c 'set -euo pipefail; echo "$UNSET_VAR"'

    परिणाम

    bash: line 1: UNSET_VAR: unbound variable

    सावधान रहें

    • Guard commands expected to return non-zero (like grep with no matches) with `|| true` or an `if` check.

    यह भी देखें

Variables & parameter expansion

Use ${...} parameter expansions for defaults, slicing and path stripping without spawning external tools.

आधिकारिक दस्तावेज़: Shell Parameter Expansion

Conditionals & tests

Prefer [[ ... ]] over [ ... ] in Bash scripts: it avoids word splitting and supports regex matching with =~.

आधिकारिक दस्तावेज़: Conditional Constructs

Loops & safe file reading

Never parse `ls` in a `for` loop. Use globs for filenames and `while IFS= read -r` for lines.

आधिकारिक दस्तावेज़: Looping Constructs

Redirection, pipes & process substitution

FD 1 is stdout (normal output), FD 2 is stderr (errors). Order matters when combining them.

आधिकारिक दस्तावेज़: Redirections

Functions, shortcuts & job control

Use readline shortcuts in your terminal and background/foreground jobs for long tasks.

आधिकारिक दस्तावेज़: Job Control

इसे KitLocal टूल में आज़माएँ

शब्दावली
Word splitting
Unquoted $var expansions split on spaces/tabs/newlines (IFS), breaking filenames with spaces.
Exit status ($?)
Integer 0..255 returned by the last command. 0 means success; any non-zero value means failure.
Parameter expansion
Transforming variables inside ${...} without spawning sed/awk subprocesses.
Subshell
A child shell created by (...) or pipes where variable changes do not affect the parent shell.

15 नव॰ 2026 को जाँचा गया · वर्शन GNU bash 5.3 के विरुद्ध जाँचा गया

स्रोत: GNU Bash Reference Manual · ShellCheck Wiki (common pitfalls)

कोण कोष्ठक में दी गई किसी भी चीज़ को अपने मानों से बदलें। कमांड आधिकारिक दस्तावेज़ों से लिए गए हैं, और उदाहरण दिखाए गए वर्शन पर चलाए गए थे।