noclobberでリダイレクトによる上書きを禁止

設定を確認

 $ set -o | grep noclobber
 noclobber       off

noclobberをオンにしてリダイレクトによる上書きを禁止する

 $ set -o noclobber
 $ touch 1.txt
 $ date > 1.txt
 -bash: 1.txt: cannot overwrite existing file

上書きしようとするとエラーが発生する。

noclobberをオフにしてリダイレクトによる上書きを禁止を解除する

 $ set +o noclobber
 $ date > 1.txt

上書きOK。

パイプを使ってnoclobbberによる上書き禁止を回避する

 $ set -o noclobber
 $ touch 1.txt
 $ date > 1.txt
 -bash: 1.txt: cannot overwrite existing file
 $ date >| 1.txt

「>|」を指定する事で上書き禁止を回避出来る。


トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS

Last-modified: 2012-09-25 (火) 00:02:00