`if [-e file.txt]` not working in bash

前端 未结 4 642
有刺的猬
有刺的猬 2021-01-18 18:46

I\'m trying to check if a file exists using bash. This is my code

if [-e file.txt]; then
  echo \"file exists\"
else
  echo \"file doesn\'t exist\"
fi
         


        
4条回答
  •  春和景丽
    2021-01-18 19:02

    Woops, turns out I needed a space between [ and -e. Like this:

    if [ -e file.txt ]; then
      echo "file exists"
    else
      echo "file doesn't exist"
    fi
    

提交回复
热议问题