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