Skip to content


การเขียน bash script เบื้องต้น

วันนี้จะทำเรื่อง svn export ก็เลยต้องมานั่งเขียน Bash script เพื่อสั่งให้ server มันไปดูดข้อมูลมา จึงได้ค้นหา website พวก tutorial เลยเอามาทำเป็นรายการรวมไว้ไน wiki ซะเลย กันลืม (เพิ่งหาได้อันเดียว) :D

จาก WikiBall

เนื้อหา



การเขียน bash script อย่างง่าย


การประกาศตัวแปร

ประการโดยการใช้ ชื่อแปร=ค่า
เรียกให้ได้โดยการใส่ $ ไว้ข้างหน้า

PROC=svn
echo $PROC


Argument

  • $0, $1, $2′,…’ — แทน argument ตัวที่ 1,2,3,…
  • $* — จำนวน argument
  • $# — เหมือนกับ $* แต่จะต่างกันเรื่องการใส่ quote เวลาเรียกใช้งาน
if [ ! -n "$1" ]
then
  echo "Usage: `basename $0` argument1 argument2 etc."
  exit $E_BADARGS
fi  

ref: Positional Parameters


Tutorial Link

รับข้อมูลจาก (Reference) :

จาก WikiBall : http://wiki.memoball.info/index.php/Bash-Scripting_tutorial

Posted in Linux. Tagged with , .

0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

Some HTML is OK

(required)

(required, but never shared)

or, reply to this post via trackback.