I'm new to bash and I can't get a script working. This is the code that I have:
#!/bin/bash
file=~/scripts/text.txt
if [ -e $file ]
then echo "The file exists"
elif [ ! -e $file ]
then echo "The file does NOT exist"
fi
sleep 1s
if [ ! -w $file ]
then { sudo chmod u+w $file; } && { echo "The file is now writable"; }
elif [ -w $file ]
then echo "The file is already writable"
fi
The top part of the script, that checks if the file exists, works just fine. The bottom part, that checks if the file is writable, partly works. It will change the permissions of the file. But after that, with write permissions enabled, it will still echo "The file is now writable" instead of "The file is already writable"
Like I said, I'm new to bash so any help would be appreciated. Please keep it simple, because if statements are about as complex as I can go with my current knowledge.
chmod
. – jordanm Aug 05 '13 at 19:44