22
17

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

bashでfileが存在するかを確認してからコマンドを実行する

Last updated at Posted at 2014-02-13

コード例

if [ -e /path/to/hoge ]; then
  # fileが存在した場合
else 
  # fileが存在しなかった場合
fi

みたいな

補足

[ <条件式> ]$ test <条件式>と同義で、testコマンドは条件式を評価して真偽を返却する。
-eがファイルが存在するかをテストする演算子みたいなやつ。
その他の演算子についてはこちらを参照するとよい。

参考

22
17
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
22
17

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?