I'd like to make this test as fast as possible: (Bash)
if [[ -d $directory_path && -r $directory_path && -x $directory_path ]]
I'd like to make this test as fast as possible: (Bash)
if [[ -d $directory_path && -r $directory_path && -x $directory_path ]]
This is as efficient as it gets.
You can see what system calls the shell makes by looking with strace (or the equivalent on unix variants other than Linux).
strace bash -c '[[ -d $directory_path && -r $directory_path && -x $directory_path ]]'
…
stat64("foo", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
faccessat(AT_FDCWD, "foo", R_OK) = 0
faccessat(AT_FDCWD, "foo", X_OK) = 0
…
That's almost as good as it gets. One system call to check the file type (-d), and one system call to check each permissions. While bash could try to deduce the access rights from the file mode, this would only work on systems with no access control lists.
The two calls to faccessat could be combined; neither bash nor ksh nor dash are clever enough to do that. But the gain would be minimal. The inode will be in the cache, so the cost of the repeated system calls will be extremely small. If you really needed that kind of microefficiency, you wouldn't be writing a shell script in the first place.