Skip to contentমূল লেখায় যান

Stage 06 · Linuxধাপ 06 · Linux · 6 topics · 19 commands6টি টপিক · 19টি কমান্ড

Shell Scripting

Automate work with variables, conditions, loops, and debugging.

UPPERCASE = your own value · red ! = can destroy data · tick a card when you know itUPPERCASE = আপনার নিজের মান · লাল ! = data নষ্ট করতে পারে · জানা হলে কার্ডে টিক দিন

0 / 6 done0 / 6 সম্পন্ন

Shell Programming

#!/bin/bash
first line: the program that runs the scriptপ্রথম লাইন: কোন program script চালাবে
chmod +x script.sh
make it executableexecutable করে
./script.sh
run itচালায়
bash script.sh
run it without the executable bitexecutable bit ছাড়া চালায়
$1 $@ $# $?
first argument · all arguments · count · last exit codeপ্রথম argument · সব argument · সংখ্যা · শেষ exit code
exit 1
stop with a status (0 = success)status দিয়ে থামে (0 = সফল)
set -euo pipefail
stop on errors, unset variables, failed pipeserror, unset variable বা pipe ব্যর্থ হলে থামে
source FILE
run a file in the current shellfile বর্তমান shell-এ চালায়

Source 1সোর্স 1Source 2সোর্স 2

Variables

NAME=VALUE
set a variable (no spaces around =)variable সেট করে (= এর দুই পাশে space নয়)
echo "$NAME"
read it (always quote it)মান পড়ে (সবসময় quote দিন)
"${NAME:-default}"
use a default if it is unsetunset হলে default মান ব্যবহার করে
read -p "Name: " NAME
ask the user for a valueuser-এর কাছে মান চায়
NAME=$(date +%F)
store the output of a commandcommand-এর output রাখে
export NAME
pass it to child processeschild process-এ পাঠায়
arr=(a b c); echo "${arr[1]}"
an array; the index starts at 0array; index ০ থেকে শুরু
$(( 2 + 3 ))
arithmeticহিসাব করে

Source 1সোর্স 1Source 3সোর্স 3

Literals

'$NAME'
single quotes: nothing expandssingle quote: কিছুই expand হয় না
"$NAME"
double quotes: variables expanddouble quote: variable expand হয়
\$ \" \\
escape a special characterবিশেষ অক্ষর escape করে
$'a\tb'
ANSI-C quotes: \t and \n workANSI-C quote: \t ও \n কাজ করে
cat <<'EOF'
here-document with no expansionexpansion ছাড়া here-document
echo -e "a\nb"
make echo read \necho-কে \n বুঝতে দেয়
printf '%s\n' TEXT
print text with a formatformat অনুযায়ী text print করে
*.txt ? [a-z]
globs: many · one · a rangeglob: অনেক · একটি · একটি range

Source 1সোর্স 1Source 4সোর্স 4

Conditionals

if [[ -f FILE ]]; then …; fi
test, then acttest করে, তারপর কাজ করে
[[ -e FILE ]]
exists (-f a file, -d a directory)আছে (-f file, -d directory)
[[ -z "$VAR" ]]
the string is emptystring খালি
[[ "$x" == "y" ]]
the strings are equalstring দুটি সমান
[[ $n -gt 5 ]]
numbers: -eq -ne -lt -gt -le -geসংখ্যা: -eq -ne -lt -gt -le -ge
CMD && CMD
run the second only if the first worksপ্রথমটি সফল হলে তবেই দ্বিতীয়টি চালায়
CMD || CMD
run the second only if the first failsপ্রথমটি ব্যর্থ হলে তবেই দ্বিতীয়টি চালায়
case "$x" in a) …;; esac
choose by patternpattern ধরে বেছে নেয়

Source 1সোর্স 1

Loops

for i in 1 2 3; do echo "$i"; done
loop over a listএকটি list ধরে loop চালায়
for f in *.txt; do …; done
loop over filesfile ধরে loop চালায়
for i in {1..5}; do …; done
count from 1 to 5১ থেকে ৫ পর্যন্ত গোনে
seq 1 5
print the numbers 1 to 5১ থেকে ৫ সংখ্যা ছাপে
while read -r line; do …; done < FILE
read a file line by linefile লাইন ধরে পড়ে
while CMD; do …; done
repeat while it succeedsসফল থাকা পর্যন্ত বারবার চালায়
until CMD; do …; done
repeat until it succeedsসফল না হওয়া পর্যন্ত বারবার চালায়
break continue
leave the loop · skip to the next roundloop ছাড়ে · পরের ধাপে যায়

Source 1সোর্স 1Source 5সোর্স 5

Debugging

bash -x script.sh
print each command as it runsপ্রতিটি command চলার সময় ছাপে
set -x / set +x
trace on · trace off, inside a scripttrace চালু · বন্ধ, script-এর ভেতরে
bash -n script.sh
check the syntax, run nothingsyntax দেখে, কিছু চালায় না
set -e
stop when a command fails (not in if/&&/||)command ব্যর্থ হলে থামে (if/&&/|| পরীক্ষায় নয়)
trap 'echo line $LINENO' ERR
report where a command failedকোথায় command ব্যর্থ হলো তা জানায়
echo "x=$x" >&2
debug print to stderrstderr-এ debug print করে
PS4='+ $LINENO: '
change the trace prefixtrace-এর prefix বদলায়
shellcheck script.sh
find common mistakes (install it first)সাধারণ ভুল খুঁজে দেয় (আগে install করুন)

Source 1সোর্স 1Source 6সোর্স 6Source 7সোর্স 7

3 min read3 মিনিটে পড়া যায় · 6 sections6টি সেকশন · 7 sources7টি সোর্স · updated Nov 2026আপডেট: Nov 2026

Reels on this topicএই টপিকের রিলস

Short videos from other creators, picked for this topic. They are not part of this page's fact-checked text. Nothing loads from YouTube until you press Play.অন্য ক্রিয়েটরদের বানানো ছোট ভিডিও, এই টপিকের জন্য বাছাই করা। এগুলো এই পেজের ফ্যাক্ট-চেক করা লেখার অংশ নয়। চালান বাটন চাপার আগে YouTube থেকে কিছুই লোড হয় না।

Sourcesসোর্স7 · accessed 2026-11-27দেখা হয়েছে: 2026-11-27

Suggest an editএডিটের পরামর্শ দিন
  1. [1]Bash Reference Manual
  2. [2]chmod(1) - change file mode bits
  3. [3]date(1) - print or set the system date and time
  4. [4]printf(1) - format and print data
  5. [5]seq(1) - print a sequence of numbers
  6. [6]bash(1) - GNU Bourne-Again SHell
  7. [7]ShellCheck: shell script analysis tool