Reputation: 16795
Is there any reason to use
if [[ ! -d dirname ]]; then mkdir dirname; fi
instead of just
mkdir -p dirname
Upvotes: 1
Views: 1207
Reputation: 4963
These two ksh commands are functionally the same since both will create a directory called dirname
.
mkdir -p dirname
is more elegant.
Upvotes: 0
Reputation: 45652
-d FILE True if file is a directory.
-p no error if existing, make parent directories as needed.
If dirname
does not contain any parents then the two commands behave the same. However if dirname
contains parents the -d
will not create those. And [[
is shell-dependent.
Upvotes: 1
Reputation: 2499
The first syntax depends on the shell you are using, not the second.
Since both fail if dirname
exists not as a directory, no, there's no difference.
Upvotes: 2