I have the following bash script:if [ -d /$home/DB_handouts] then echo Directory DB_handouts foundelsemkdir /$home/DB_handouts chmod 777 /$home/DB_handoutsfiRunning the above code produces an error:./file.sh: line 12: syntax error near unexpected token `else'./file.sh: line 12: `   else'How can I fix this?
use of if else in linux to find whether the folder exists or not
bash;shell script;mkdir
There are multiple problems with your script:there has to be a ; between the ] and then (as @heemayl also indicated) or then should be put on a line of its ownthere has to be a space between handouts and ]you should (but this doesn't generate an error) consistently indent, or use the -m option for mkdir (as @skwlisp indicated)something like:if [ -d /$home/DB_handouts ] then  echo Directory DB_handouts foundelse  mkdir -m 777 /$home/DB_handoutsfiThe above of course assumes that /$home exists, the whole thing can be much more easily achieved by using:mkdir -p -m 777 /$home/DB_handoutsWith -p there will be no complaints if the directory already exists.