Hey guys im trying to check if the directory exists
i get a syntax error on the elif statement iv tried using else and still same result im not sure. If the directory does not exist can i just insert mkdir /tmp/old under the elif once that part gets working
if [ -d $/tmp/old ]; then
#do nothing
elif
echo "Error: '$check' does not exist!!"
echo "EXITING"
exit 1
fi
if [ -d /tmp/old ]
then
#do nothing
elif
echo "directory exists"
exit 1
fi
i get some weird errors all about syntax where am i going wrong
Replace elif by else.
A comment is not evaluated as an statement, she shell will signal a syntax error on the else line. A null statement is specified with ':' :if [ -d /tmp/old ]
then
: #do nothing
else
echo "directory exists"
exit 1
fi
You can also invert your test :
if [! -d /tmp/old]
then
echo "directory exists"
exit 1
fi
"If not directory /tmp/old then echo directory exists"? I think you got that backwards.
If the topic title of this thread is any indication then mkdir -p /tmp/old is all that's needed. If the directory exists, nothing happens. If it doesn't exist, it's created.