1
1

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.

シェルスクリプトでディレクトリが存在しない場合のみディレクトリを作成する

Last updated at Posted at 2020-01-06

シェルスクリプトで特定のディレクトリの存在を確認し、存在しなければ作成する。

./exampleが存在しなければ作成する。

if [ ! -d ./example ]; then
  mkdir ./example
fi

後から知った(ご教示いただいた)が、-pオプションでも同様のことが可能。
ディレクトリがすでに存在していても、エラーメッセージが表示されない。

mkdir -p ./example
1
1
2

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?