* noclobberでリダイレクトによる上書きを禁止 [#cff7c7a9]


** 設定を確認 [#j306f99e]
 $ set -o | grep noclobber
 noclobber       off

** noclobberをオンにしてリダイレクトによる上書きを禁止する [#w1b9edab]
 $ set -o noclobber
 $ touch 1.txt
 $ date > 1.txt
 -bash: 1.txt: cannot overwrite existing file
上書きしようとするとエラーが発生する。

** noclobberをオフにしてリダイレクトによる上書きを禁止を解除する [#w02c75e7]
 $ set +o noclobber
 $ date > 1.txt
上書きOK。

** パイプを使ってnoclobbberによる上書き禁止を回避する [#t8374d66]
 $ set -o noclobber
 $ touch 1.txt
 $ date > 1.txt
 -bash: 1.txt: cannot overwrite existing file
 $ date >| 1.txt
「>|」を指定する事で上書き禁止を回避出来る。


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