farmer-logo.gif (14959 bytes) cshell-logo.gif (19625 bytes)
ch-4.gif (10100 bytes)
main-b.gif (271 bytes)


mail.gif (2925 bytes)

4-2-13 noclobber 禁止覆寫變數

這個 noclobber 變數我們在前面的輸出重導向章節中已經提過,它的功能便是停止重導向符號“>”的覆寫(overwiting)已存在檔案以及符號“>>”要將資料寫入一個不存在的檔案時,自動產生該檔案的特性。我想在此便不再贅述,僅用兩個例子讓讀者回憶一下,設定後的實際使用狀況。

例子一:

% ps axu > testfile
% set noclobber
% echo "test set noclobber" > testfile
testfile: File exists.
% echo "test set noclobber" >! testfile
%

例子二:

% set noclobber
% cat /etc/passwd >> nopass
nopass: No such file or directory
% cat /etc/passwd >>! nopass
%

b-line.gif (2092 bytes)