Skip to main content
added 113 characters in body
Source Link
Barmar
  • 10.6k
  • 1
  • 22
  • 29

Your command can fail if dir1/dir2 exists but is not a directory. If you want to test whether dir1/dir2 exists at all, use -e

[ -e dir1/dir2 ] || mkdir dir1/dir2

You couldIf you really need dir1/dir2 to be a directory, and an ordinary file with that name is an error and should be replaced, you can test for this possibility:that case.

[ -e dir1/dir2 ] && [ ! -d dir1/dir2 ] && rm dir1/dir2
[ -d dir1/dir2 ] || mkdir dir1/dir2

Your command can fail if dir1/dir2 exists but is not a directory. If you want to test whether dir1/dir2 exists at all, use -e

[ -e dir1/dir2 ] || mkdir dir1/dir2

You could test for this possibility:

[ -e dir1/dir2 ] && [ ! -d dir1/dir2 ] && rm dir1/dir2
[ -d dir1/dir2 ] || mkdir dir1/dir2

Your command can fail if dir1/dir2 exists but is not a directory. If you want to test whether dir1/dir2 exists at all, use -e

[ -e dir1/dir2 ] || mkdir dir1/dir2

If you really need dir1/dir2 to be a directory, and an ordinary file with that name is an error and should be replaced, you can test for that case.

[ -e dir1/dir2 ] && [ ! -d dir1/dir2 ] && rm dir1/dir2
[ -d dir1/dir2 ] || mkdir dir1/dir2
Source Link
Barmar
  • 10.6k
  • 1
  • 22
  • 29

Your command can fail if dir1/dir2 exists but is not a directory. If you want to test whether dir1/dir2 exists at all, use -e

[ -e dir1/dir2 ] || mkdir dir1/dir2

You could test for this possibility:

[ -e dir1/dir2 ] && [ ! -d dir1/dir2 ] && rm dir1/dir2
[ -d dir1/dir2 ] || mkdir dir1/dir2