※ 引述《CMrockmanx (rockman)》之銘言:
原本看到的時候想回答的,但是一開始打的時候,卻又發現很難,
所以決定要查一查資料以後再回你,不過現在也很晚了,改天再給
implementation 。
: 1.有些shell所提供的alias功能並不能作參數傳遞.
: 現在, 假如我在計中的機器上是使用bash, 而我要寫一個有關 find 的alias, 如下:
: % find S_DIR -name FILENAME 2> /dev/null
: 其中,S_DIR是search directory(default / directory),FILENAME是target file.
: 我要如何能直接在prompt 下鍵入:
: % f FILENAME S_DIR
: shell就會自動的執行我要的動作呢? (Note: S_DIR 是 optional, 可不提供).
聽說,大概只有 csh, tcsh 那一派的, alias 才能傳遞參數。
底下,引出一段 bash 的 document:
There is no mechanism for using arguments in the replacement text,
as in `csh'. If arguments are needed, a shell function should be used.
所以,唯一的方法,大概就是用 function 。
: 2.Regular Expression 在很多filter tools (e.g. sed, awk, perl)中是很重要的.
: 假如,我有一個file內容是中文字,英文字母(A-Z,a-z)與數字(0-9)任意參雜的file.
: 請使用sed or awk or perl將file轉成一行只有一個中文字或英文字母或數字的
: 新檔案.
就這個程式來講的話,每次應該要讀一個 character 進來,然後要判斷是不
是中文字的第一個 byte ,如果是,就再讀一個 char 進來,湊成一行。
如果不是,就直接送成一行。概念很簡單,要做起來好像不容易呢。
--
※ 發信站: 批踢踢實業坊(ptt.m8.ntu.edu.tw)
◆ From: Port37.TS2.neto