samedi 21 mars 2020

How to solve Linux If-Else statement syntax error?

I am trying to check whether a directory already exists or not inside a case-control statement. But it is giving an error in 'then' statement.

case $choice in
1)echo "Enter directory name: "
  read dname
  mkdir $dname
  if[-d "$dname"]
  then
     echo "$dname directory already exists."
  else
     echo "$dname directory successfully created."
  fi
  read
  ;;

error message:

uan.sh: line 13: syntax error near unexpected token `then'
uan.sh: line 13: `  then'

Aucun commentaire:

Enregistrer un commentaire