Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> ระบบ >> Windows

วิธีรันไฟล์ .sh หรือ Shell Script บน Windows 11/10

Shell Script (.sh) คือไฟล์สคริปต์ของ Linux/Unix สามารถรันบน Windows ได้ 2 วิธีหลัก:

1. ใช้ WSL (Windows Subsystem for Linux) - แนะนำ

  1. Settings > Update & Security > For Developers > เปิด Developer Mode
  2. ค้นหา "Turn Windows features on or off" > ติ๊ก Windows Subsystem for Linux > Restart
  3. เปิด Command Prompt/PowerShell > พิมพ์ bash เข้าสู่ Bash
  4. ไปที่โฟลเดอร์ไฟล์ .sh > รัน bash script-filename.sh

2. ใช้ Ubuntu บน Windows (Microsoft Store)

  1. ติดตั้ง Ubuntu จาก Microsoft Store
  2. เปิด Ubuntu > ไปที่โฟลเดอร์ไฟล์ (Windows drives อยู่ที่ /mnt/c/)
  3. รัน sh script.sh หรือ bash script.sh

หมายเหตุ: WSL เพียงพอสำหรับสคริปต์ส่วนใหญ่ หากต้องการ Kernel จริง ให้ใช้ Ubuntu/WSL 2