UNIX Shell Script
出自KMU Wiki
(修訂版本間差異)
在2008年5月6日 (二) 19:14所做的修訂版本 (編輯) Cch (對話 | 貢獻) (新頁面: ==Bourne shell(sh)== === Variable === YOURVAR=some echo $YOURVAR echo ${YOURVAR} === Flow control === if [ -f your_file ]; then echo "your_file exists" fi for f in a b c ...) ←上一個 |
當前修訂版本 (2008年5月7日 (三) 22:05) (編輯) (撤銷) Cch (對話 | 貢獻) |
||
(7個中途的修訂版本沒有顯示。) | |||
第1行: | 第1行: | ||
- | == | + | === 動機 === |
+ | |||
+ | 為什麼要學 Shell Script | ||
+ | |||
+ | * automatic (自動化) | ||
+ | * batch (批次) | ||
=== Variable === | === Variable === | ||
YOURVAR=some | YOURVAR=some | ||
+ | MYVAR=thing | ||
echo $YOURVAR | echo $YOURVAR | ||
- | echo ${YOURVAR} | + | echo ${YOURVAR}${MYVAR} |
- | + | ||
=== Flow control === | === Flow control === | ||
- | |||
if [ -f your_file ]; then | if [ -f your_file ]; then | ||
- | + | echo "your_file exists" | |
+ | else | ||
+ | echo "your_file not exists" | ||
fi | fi | ||
- | |||
for f in a b c | for f in a b c | ||
do | do | ||
- | + | echo $f | |
done | done | ||
第25行: | 第30行: | ||
sub() | sub() | ||
{ | { | ||
- | + | echo $1 $2 $3 | |
- | + | ||
} | } | ||
- | |||
sub X Y Z | sub X Y Z | ||
=== Examples === | === Examples === | ||
- | #!/bin/sh | + | #!/bin/sh |
exec < $1 | exec < $1 | ||
- | while | + | while read line |
do | do | ||
- | + | echo $line | |
done | done | ||
- | == | + | === 學習資源 === |
+ | |||
+ | [http://www.mgt.ncu.edu.tw/~dino/script/ http://www.mgt.ncu.edu.tw/~dino/script/] |
當前修訂版本
目錄 |
[編輯] 動機
為什麼要學 Shell Script
- automatic (自動化)
- batch (批次)
[編輯] Variable
YOURVAR=some MYVAR=thing echo $YOURVAR echo ${YOURVAR}${MYVAR}
[編輯] Flow control
if [ -f your_file ]; then echo "your_file exists" else echo "your_file not exists" fi
for f in a b c do echo $f done
[編輯] Sub Program
sub() { echo $1 $2 $3 } sub X Y Z
[編輯] Examples
#!/bin/sh exec < $1 while read line do echo $line done