I am getting the error: ./Lab17Part3: line 4: [: missing `]' when I try to run this code. Oddly enough, it then continues to work as intended.
#!/bin/sh
#Delete a file interactively
filename=$1
if [ !-f $filename && !-d $filename ]
then
echo "There is no file \"$filename\"."
else
echo "Do you want to delete \"$filename\"?"
read choice
if test $choice = y
then
if [ -d $filename ]
then
rmdir $filename
echo \"$filename\" deleted
else
rm $filename
echo \"$filename\" deleted
fi
else
echo \"$filename\" not deleted.
fi
fi
Why am I getting the error, as my line for definitely has a ']' to terminate it. I don't think there are any other syntax things missing. I remembered to have a space before the ']'.