ชุดคำสั่งที่ทำงานตามลำดับ
พื้นที่ฝึก
Bash
เส้นทางฝึก Bash ตั้งแต่ศูนย์
นิยามก่อน
Bash คืออะไร
Bash ใช้เขียนคำสั่งที่ชัดเจน ที่นี่เรียนเป็น เส้นทางฝึก Bash ตั้งแต่ศูนย์ เริ่มจากภาพเดียว input ผ่านขั้นตอนแล้วกลายเป็น output
script.shรัน bash script.shนิสัย เรียน Bash ทีละส่วนเล็ก แล้วพิมพ์ตัวอย่างสั้นและรันค่าคือข้อมูล ตัวแปรคือชื่อที่เก็บข้อมูล
งานย่อยที่มีชื่อ รับ input และสร้างผลลัพธ์
POSIX shell compatible terminal รันโค้ดจาก script.sh
โค้ดแรกที่อ่านง่าย
Commands
pwd ls cd echoname="Ada" echo "$name"
ผลลัพธ์ Adaตระกูลภาษา
ผังตระกูล Bash
ดูว่า Bash มาจากไหน ใกล้กับภาษาใด และควรเรียนอะไรต่อ
เหมาะกับ เส้นทางฝึก Bash ตั้งแต่ศูนย์
เริ่มจากศูนย์
คลังคำถาม
ค้นหาก่อนฝึก
เลือกขั้นหรือค้นหาแบบฝึกของภาษานี้ แล้วเปิดข้อที่ต้องการทันที
Bash ข้อ 1
Bash ข้อ 1 เลือกคำอธิบายที่ตรงกับ echo output ที่สุด
Bash ข้อ 2
Bash ข้อ 2 เลือกคำอธิบายที่ตรงกับ variable assignment ที่สุด
Bash ข้อ 3
Bash ข้อ 3 เลือกคำอธิบายที่ตรงกับ pipe ที่สุด
Bash ข้อ 4
Bash ข้อ 4 เลือกคำอธิบายที่ตรงกับ for loop ที่สุด
Bash ข้อ 5
Bash ข้อ 5 เลือกคำอธิบายที่ตรงกับ echo output ที่สุด
Bash ข้อ 6
Bash ข้อ 6 เลือกคำอธิบายที่ตรงกับ variable assignment ที่สุด
Bash ข้อ 7
Bash ข้อ 7 เลือกคำอธิบายที่ตรงกับ pipe ที่สุด
Bash ข้อ 8
Bash ข้อ 8 เลือกคำอธิบายที่ตรงกับ for loop ที่สุด
Bash ข้อ 9
Bash ข้อ 9 เลือกคำอธิบายที่ตรงกับ echo output ที่สุด
Bash ข้อ 10
Bash ข้อ 10 เลือกคำอธิบายที่ตรงกับ variable assignment ที่สุด
Bash ข้อ 11
Bash ข้อ 11 เลือกคำอธิบายที่ตรงกับ pipe ที่สุด
Bash ข้อ 12
Bash ข้อ 12 เลือกคำอธิบายที่ตรงกับ for loop ที่สุด
Bash ข้อ 13
Bash ข้อ 13 เลือกคำอธิบายที่ตรงกับ echo output ที่สุด
Bash ข้อ 14
Bash ข้อ 14 เลือกคำอธิบายที่ตรงกับ variable assignment ที่สุด
Bash ข้อ 15
Bash ข้อ 15 เลือกคำอธิบายที่ตรงกับ pipe ที่สุด
Bash ข้อ 16
Bash ข้อ 16 เลือกคำอธิบายที่ตรงกับ for loop ที่สุด
Bash ข้อ 17
Bash ข้อ 17 เลือกคำอธิบายที่ตรงกับ echo output ที่สุด
Bash ข้อ 18
Bash ข้อ 18 เลือกคำอธิบายที่ตรงกับ variable assignment ที่สุด
ปรนัย
Bash ข้อ 1
Bash ข้อ 1 เลือกคำอธิบายที่ตรงกับ echo output ที่สุด
echo "$name"
อ้างอิง
รูปแบบของ script.sh
bash script.shpwd ls cd echo
Commands
name="Ada" echo "$name"
- Quote variables
- Start with echo
- Run in a small folder first
grep sort uniq wc
Pipes
printf "a\na\nb\n" | sort | uniq
- Pipe output to the next command
- Use rg or grep for search
- Count with wc
shebang variables if loops
Scripts
for file in *.txt; do echo "$file" done
- Use set -e for safer scripts
- Quote paths
- Dry run before deleting