3
3

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 3 years have passed since last update.

シェルスクリプト ファイルの存在で条件分岐

Posted at

#ファイルやディレクトの存在の有無で条件分岐させたい 備忘録

-eオプションとif文を組み合わせる

「既にファイルが存在するなら、実行したい。」場合

#!/bin/bash
filename=hoge

if [ -e $filename];then
  echo "$filename exists"
fi

「すでにファイルが存在するなら余計なことはしなくない」という場合
否定論理にしたいなら -e の前に ! をつける

#!/bin/bash
filename=hoge

if [ !-e $filename];then
mkdir $filename

以上

3
3
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
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?