Overview
Shell scripts (.sh files) මගින් Linux සහ macOS වල tasks automate කරනවා, නමුත් Windows ඒවා natively run කරන්නේ නෑ. ඒවා run කරන්න හොඳම ක්රමය Windows Subsystem for Linux (WSL) — මේකෙන් Windows ඇතුළේ real Linux environment එකක් ලබා දෙනවා. මේ guide එකෙන් WSL සහ alternative tools පාවිච්චි කරලා .sh scripts run කරන හැටි පෙන්නනවා.
WSL හෝ Git Bash පාවිච්චි කරලා Windows එකේ Linux shell scripts run කරන්න.
Key Takeaways
- Windows එකට .sh scripts natively run කරන්න බෑ — WSL හෝ Unix-style shell එකක් පාවිච්චි කරන්න.
- WSL එකෙන් bash එක්ක genuine Linux environment එකක් ලබා දෙනවා.
- Git Bash සහ Cygwin simple scripts වලට lighter alternatives.
- chmod +x එකෙන් script එකක් executable කරලා ./script.sh එකෙන් run කරන්න.
What Are Shell (.sh) Files?
.sh file එකක් කියන්නේ Unix shell එකකට (සාමාන්යයෙන් bash) commands තියෙන text file එකක්. Repetitive tasks automate කරන්න පාවිච්චි කරනවා. එය Linux/Unix shell එක target කරන නිසා, Windows එකේ run වෙන්න compatible shell environment එකක් අවශ්යයි.
Method 1 — Run With WSL (Recommended)
1. PowerShell එක administrator විදිහට open කරලා run කරන්න: wsl --install
2. PC එක restart කරලා, default Linux distribution එක (Ubuntu) setup එක අවසන් වෙන්න දෙන්න — username සහ password එකක් හදාගන්න.
3. Linux terminal එක open කරලා, ඔබේ script එකට navigate කරන්න: cd /mnt/c/Users/YourName/Scripts
4. Script එක executable කරන්න: chmod +x script.sh
5. Run කරන්න: ./script.sh
Note: ඔබේ Windows drives WSL එකේ /mnt/ යටතේ available — උදාහරණයක් විදිහට C: කියන්නේ /mnt/c.
Method 2 — Run With Git Bash
1. Git for Windows download කරලා install කරන්න — එකට Git Bash ඇතුළත් වෙනවා.
2. ඔබේ script එක තියෙන folder එකේ right-click කරලා Git Bash Here තෝරගන්න.
3. Script එක run කරන්න: ./script.sh (හෝ bash script.sh).
Method 3 — Other Tools
- Cygwin — Windows එකේ Unix tools විශාල එකතුවක් සහ bash shell එකක් ලබා දෙනවා.
- MSYS2 — software build කරන්න popular Unix-like environment එකක්.
- Full WSL setup එකක් නැතුව Unix utilities ඕන කරන කොට මේවා පාවිච්චි කරන්න.
How to Create a Shell Script
1. Notepad හෝ VS Code වගේ plain-text editor එකක් open කරන්න.
2. File එක shebang line එකෙන් පටන් ගන්න: #!/bin/bash
3. ඔබේ commands add කරන්න — line එකකට එකක්.
4. File එක .sh extension එකකින් save කරලා (WSL/bash එකේ) chmod +x එකෙන් executable කරන්න.
Frequently Asked Questions
Problem: Windows එකේ shell scripts run කරන්න පුළුවන්ද?
Solution: ඔව් — natively නෙවෙයි, නමුත් WSL, Git Bash, Cygwin, හෝ MSYS2 හරහා — ඒවා compatible shell එකක් ලබා දෙනවා.
Problem: ./script.sh run කරන කොට "Permission denied".
Solution: මුලින්ම script එක executable කරන්න: chmod +x script.sh, ඊට පස්සේ ./script.sh run කරන්න.
Problem: Script එක run වෙනවා, නමුත් commands "not found".
Solution: Script එකේ ඔබේ shell එකේ නැති Linux tools තියෙන්න ඇති. Full Linux compatibility එකට WSL පාවිච්චි කරන්න.
Problem: Line-ending errors (\r) පෙන්නනවා.
Solution: File එකේ Windows line endings තියෙනවා. dos2unix එකෙන් convert කරන්න, නැත්නම් editor එකේ Unix (LF) line endings එකෙන් save කරන්න.
Conclusion
WSL කියන්නේ Windows එකේ shell scripts run කරන්න වඩාත් complete ක්රමය — real Linux environment එකක් ලබා දෙනවා. Quick scripts වලට Git Bash lightweight alternative එකක් — chmod +x සහ ./script.sh මතක තියාගන්න.
About TechHub
මේ guide එක TechHub Knowledge Base එකේ කොටසක්. තව step-by-step IT guides සහ support වලට techhub.com.lk එකට යන්න.















