মূল বিষয়বস্তুতে যান
kitlocal.dev

Bash চিটশিট

লোকালি চলে

১০০% আপনার ব্রাউজারে প্রসেস হয়। ইনপুট ও আউটপুট কখনো আপনার ডিভাইস ছেড়ে যায় না।

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.

সারভাইভাল কিট

যে কয়েকটি কমান্ড সবার আগে শিখতে হবে।

৪১টি কমান্ড

কীবোর্ড শর্টকাট/সার্চে ফোকাস করুন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.

১৫ নভে, ২০২৬ তারিখে যাচাইকৃত · GNU bash 5.3-এর বিপরীতে যাচাইকৃত

উৎস: GNU Bash Reference Manual · ShellCheck Wiki (common pitfalls)

অ্যাঙ্গেল ব্র্যাকেটের ভেতরের অংশগুলো আপনার নিজস্ব মান দিয়ে প্রতিস্থাপন করুন। কমান্ডগুলো অফিসিয়াল ডকুমেন্টেশন থেকে নেওয়া হয়েছে এবং প্রদর্শিত সংস্করণে উদাহরণগুলো পরীক্ষা করা হয়েছে।