Lập trình bằng shell... Cấu trúc lặp... Cấu trúc lặp – ví dụ... variables are used by shell... creates a basic web page, complete with title & primary headline readline function use
Trang 1LẬP TRÌNH SHELL
Trang 2Nội dung
Trang 3Lập trình bằng shell
Trang 4Đặc trưng của script
Trang 5Cấu trúc shell-script
Trang 6Create File & Run Script
Trang 7Review commands
Trang 8Parameter & Variables
Trang 9Positional Parameters
Trang 10Giá trị default của tham số
Trang 11Shift
Trang 13Khác nhau giữa * và @
Trang 14Biến tiền định nghĩa
Trang 15Lệnh nội trú
Trang 16Echo
Trang 17Echo – ví dụ
Trang 18Example for ouput’s format
Trang 19Result
Trang 20Read
Trang 21Command Substitution
Trang 22Exit Status
Trang 23Cấu trúc If
Trang 24If – ví dụ
Trang 25If ví dụ
Trang 26Cấu trúc case
Trang 27Test
Trang 28Example
Trang 29Test
Trang 30Example
Trang 31Test
Trang 33Test ví dụ
Trang 34Cấu trúc lặp
Trang 35Cấu trúc lặp – ví dụ
Trang 38Break
Trang 39continue
Trang 40Định hướng với if
Trang 43Array
Trang 44Assigning Array Elements
Trang 45next unassigned element
Trang 46entire array with a single cmd
Trang 47+= used to append values to end of indexed array
Trang 48Associative Arrays
use strings as subscripts
must be declared before being used
Trang 49Hàm
Trang 50Check Argument for Valid Dotted-Quad IP Address
Trang 52Gọi hàm
Trang 53Thực hiện
Trang 54Test isvalidip
Trang 56Example
Trang 58Return
Trang 59Exit
Trang 60Function Libraries
Trang 61Debug
Trang 62Set
Trang 63variables are used by shell
Trang 64variables are set by shell
Trang 65 creates a basic web page, complete
with title & primary headline (<H1>)
readline function uses options to builtin command read
Trang 72 Tạo bài hát mới
Sửa đổi thông tin về bài hát
Xóa bài hát
Liệt kê danh mục bài hát
Trang 73 Tệp lưu thông tin về CD (ID, tên, kiểu, NSX, )
Tệp lưu thông tin bài hát(CD’s ID, tên, track,tác giả,
ca sĩ)
Dùng các ký tự CVS phân cách các cột
Trang 74 Các hàm cho các chức năng xử lý bài hát
Thêm, Xóa, Cập nhật thông tin bài bát
Liệt kê, Tìm các bài hát hiện có
Trang 76Echo “l List tracks of $cdtitle”
Echo “r remove $cdtitle”
Echo “u Update $cdtitle”
Trang 77Read tmp cdtitle = ${tmp%%,*}
if [“$tmp” != $cdtitte] then echo “Format invalid”
continue fi
if [-n $cdtitle] then
if [“$cdtitle” != ‘q’] then insert_track $cdcatnum, $cdtrack,
$cdtitle fi else
cdtrack; = $((cdtrack -1)) fi
cdtrack = $((cdtrack +1)) done
}
Trang 80a add_record;;
r remove_record;;
….
esac Done
Rm –f $temp_file Exit 0
Trang 81File Operations & Commands
how shell works with files
shell options that
modify & extend file name expansion
read and modify contents of files.
Several external cmd that work on files
Trang 82Reading a File
Trang 83kjv.txt
Trang 841(more) variable be supplied
as args to read
Trang 85Word splitting
Trang 87Result
Trang 89examples
Trang 90modifying a file
Trang 91File Name Expansion Options
Trang 92 six shell options that affect way in which file names are expanded.
shopt command
-s enable
-u disable
Trang 93Ex: various globbing options
Trang 94nullglob
Trang 95failglob
Trang 96dotglob
Trang 98Example
Trang 103nocaseglob
Trang 105 allows use of ** to descend recursively into
directories &subdirectories looking for matching files
Trang 106review