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
[ is not a special token in Bash; it's just that the word [ is a builtin command (just like echo). So you need a space after it. And, similarly, you need a space before ]:
if [ -e file.txt ] ; then
That said, I recommend [[ ]] instead — it's safer in a few ways (though it still requires the spaces):
if [[ -e file.txt ]] ; then