I want to check if a directory exists and it has access rights; if it does, then perform the tasks. This is the code I wrote, which might not have proper syntax.
Can you help me to correct it?
dir_test=/data/abc/xyz
if (test -d $dir_test & test –x $dir_test -eq 0);
then
cd $dir_test
fi
I believe this can also be written like this.
dir_test=/data/abc/xyz
test -d $dir_test
if [ $? -eq 0 ];
then
test –x $dir_test
if [ $? -eq 0 ];
then
cd $dir_test
fi
fi
How can we write this more efficiently?