|

楼主 |
发表于 2003-2-7 02:59:02
|
显示全部楼层
二、指令功能
1.別名-alias
alias 查看別名清單
alias 別名='指令敘述' 設定別名
[guo@amigo guo]$alias
alias cp='cp -i'
alias l.='ls .[a-zA-Z]* --color=tty'
alias ll='ls -l --color=tty'
alias ls='ls --color=tty'
alias mv='mv -i'
alias rm='rm -i'
[guo@amigo guo]$alias copy='cp'
[guo@amigo guo]$alias
alias copy='cp'
alias cp='cp -i'
alias l.='ls .[a-zA-Z]* --color=tty'
alias ll='ls -l --color=tty'
alias ls='ls --color=tty'
alias mv='mv -i'
alias rm='rm -i'
[guo@amigo guo]$
2.指令記錄(history)
[guo@amigo guo]$history|more
220 ls -l
221 cd /var
222 ls
223 ls -l
[guo@amigo guo]$!220
[guo@amigo guo]$!!
3.自動完成指令
his Tab
[guo@amigo guo]$history
三、輸出/輸入(I/O)導向(Redirection)
在Linux系統中每一個程式(process),都會有輸出、輸入及錯誤輸出三個通道(channel),分別為標準輸入(stdin)、標準輸出(stdout)及標準錯誤輸出(stderr)。導向的功能主要在於控制輸出、輸入及錯誤輸出檔案,可隨意變更標準輸入(stdin)、標準輸出(stdout)及標準錯誤輸出(stderr)檔案。
[guo@amigo shell]$ls
argument bash case2 catall doctotxt fordo hello1 read
backup case1 case3 checkf exit1 hello listbin txttodoc
[guo@amigo shell]$ls >yy
[guo@amigo shell]$
1.導向控制
a.指令< 檔案
mail guo < file
b.指令>檔案
ls > yy
c.指令>>檔案
date>>yy
d.指令A|指令B
ls|more
ls|sort>file
四、工作控制功能(Jobs Control)
1.工作與行程
info make
Ctrl+Z
vi test
Ctrl+Z
mail guo
Ctrl+Z
jobs
ps
2.前景與背景
ls (前景處理)
ls& (背景處理)
3.顯示工作
jobs
4.控制工作
指定工作
%編號
%字串
%%
%-
例如:
fg %1
bg %2
kill %1
肆、shell script撰寫
一、建立與執行shell script
1.建立一個shell script檔
vi hello (內容如下)
[guo@amigo shell]$ more hello
#!/bin/sh
# Filename : hello
echo "Hello world!"
a.編寫一個shell script檔內容
b.chmod 755 hello
2.執行shell script
a. ./hello
b.bash hello
c.source hello
d. . hello (root才能使用)
二、變數
1.設定變數
a.直接設定
格式:變數=值
x=hello
b.使用read指令
echo 'What is your name ?'
read name
echo 'Hello! '$name
c.指令取代
y=`date`
echo $y
d.指令參數
格式:指令 參數1 參數2 參數3….
[guo@amigo shell]$ more argument
#!/bin/sh
# Filename : argument
echo 'argument1 is '$1
echo "argument2 is "$2
echo "argument3 is "$3
[guo@amigo shell]$ ./argument AA BB CC
argument1 is AA
argument2 is BB
argument3 is CC
2.變數的使用
$變數名稱
echo $x
3.變數宣告後其他 subshell也可以使用該變數
格式:export 變數名稱
export x
三、控制結構
test的使用(參考範例一、二)
case .. esac的使用(參考範例三)
if .. then .. fi的使用(參考範例四、五)
for .. in .. do .. done的使用(參考範例六)
while .. do .. done的使用(參考範例七、八)
until .. do .. done的使用(參考範例九)
參考範例一
[guo@amigo shell]$ test b = a
[guo@amigo shell]$ echo $?
1
[guo@amigo shell]$ test b = b
[guo@amigo shell]$ echo $?
0
參考範例二
[guo@amigo shell]$ [ b = a ]
[guo@amigo shell]$ echo $?
1
[guo@amigo shell]$ [ b = b ]
[guo@amigo shell]$ echo $?
0
參考範例三
[guo@amigo shell]$ more case1
#!/bin/sh
# Filename : case1
case $1 in
start | begin)
echo "start somthing"
;;
stop | end)
echo "stop somthing"
;;
*)
echo "nothing"
;;
esac
參考範例四
[guo@amigo shell]$ more ifthen
#!/bin/sh
# Filename : ifthen
echo "Are you O.K.(y/n)?"
read answer
if [ "$answer" = Y -o "$answer" = y ]
then
echo "Glad to hear it."
fi
參考範例五
[guo@amigo shell]$ more ifthenelse
#!/bin/sh
# Filename : ifthen
echo "Are you O.K.(y/n)?"
read answer
if [ "$answer" = Y -o "$answer" = y ]
then
echo "Glad to hear it."
else
echo "I am sorry."
fi
參考範例六
[guo@amigo shell]$ more doctotxt
#!/bin/sh
# Filename : doctotxt
FILES=`ls /home/guo/test/*.doc`
for doc in $FILES
do
txt=`echo $doc | sed "s/.doc/.txt/"`
mv $doc $txt
done
參考範例七
[guo@amigo shell]$ more while1
#!/bin/sh
num=0
while [ $num -lt 10 ]
do
echo $num
num=`expr $num + 1 `
done
echo "while end"
參考範例八
[guo@amigo shell]$ more while2
#!/bin/sh
echo "Guess a number,Please input a number :"
read num
while [ "$num" != "7" ]
do
echo "Wrong try again!"
read num
done
echo You got it!
參考範例九
[guo@amigo shell]$ more until1
#!/bin/sh
num=0
until [ $num -gt 10 ]
do
echo $num
num=`expr $num + 1 `
done
echo "until end"
JOE 編輯器
一. 概述
JOE 是一種全螢幕的編輯器,它是由 Joseph H. Allen 撰寫出?,可用?
編輯程式檔案及一般文字檔案。如果您需要 help , 請按 Ctrl-K-H 後, 會在
Windows 最後一行出現 Basic Windows Advanced Options Search Names
Joe 等文字, cursor 停留在 Basic 上, 您可以使用左右鍵選您要 help 的項,
再 Return 即可,取消 help 請再按一次 Ctrl-K-H 後即消失。(以下內容所有
Ctrl 鍵,將以 ^ 符號代替,如 Ctrl-K-H 將以 ^KH 取代之)
二. 啟動 JOE
%joe
或
%joe filename
三. JOE 指令集
1. 游標控制指令
^B 往左移一個字元(char) ^F 往右移一個字元
^Z 往左移一個字(word) ^X 往右移一個字
^P 往上移一行 ^N 往下移一行
^A 游標移至行首 ^E 游標移至行尾
^U 往上移一頁 ^V 往下移一頁
^KU 游標移至檔首 ^KV 游標移至檔尾
^KL 游標移至某行
2. 刪除指令
^D 刪除游標所在的字元 ^Y 刪除游標所在的行
^O 往左刪除一個字(word) ^W 往右移珊除一個字
^J 刪除?挠螛怂谧衷列形
^- undo ^^ redo
3. 區塊指令
^KB 定址區塊起始點 ^KK 定址區塊終止點
^KC 區塊拷? ^KM 區塊般移
^KW 區塊儲存 ^KY 區塊刪除
4. 搜尋和取代指令
^KF 尋找字串
說明:在螢幕最下面會有一行,提示您輸入欲尋找的字串
Search string (^C to abort):define
按<return>後,提示畫面如下:
(I)gnore case (B)ackwards (R)eplace n (^C to abort):
可輸入 I 或 B 或 R
I: 忽略大小寫
B: ?挠螛怂谖恢猛皩ふ
R: 將出現另一提示畫面要求輸入欲取代之字串
^L 繼續尋找前一次尋找之字串
5. 有關 Window 的指令
^KO 分割畫面(把一個畫面分割兩成二個畫面)
^KI 顯示一個視窗或全部視窗
^KP 將游標移至上一個視窗 ^KN 將游標移至下一個視窗
^KT 將游標所在的視窗範圍縮小 ^KG 將游標所在的視窗範圍放大
6. 讀取檔案的指令
^KE 讀取檔案
^KR 讀取一檔案,存入目前開啟之檔案,游標所在行之後
7. 存檔與離開 JOE 的指令
^KX 存檔且離開 JOE
^KD 存檔但仍在 JOE 狀態下
^C 不儲存被修改之檔案,直接離開 JOE
8. 其它的指令
^TT Insert/Overtype
^TA Autoindent on/off
^TL 設定左邊界
^TR 設定右邊界
^TP 設定 PgUp/PgDn 的行數
^TD 設定 TAB 的長度
^KA 使整行文字向中對齊
^KZ 暫時離開 JOE 到 UNIX 系統下,欲回到 JOE,請輸入 fg
^K, 整個區塊(block)或段落(paragraph)向左移一個 bype
^K. 整個區塊(block)或段落(paragraph)向右移一個 bype
^KO 執行 UNIX 指令 |
|