Reputation: 11
For quite some time now I have been struggling with this little code segment.
#!/bin/bash
testFunction() {
if [ -d "/home/$USER/.skandPATH/" ] ; then
#Exists. Do nothing.
else
mkdir /home/$USER/.skandPATH/ #Does not exist. Creates directory
addedPathDir=1
fi
}
testFunction
Every time I run it I get the following message:
./functionInScript.sh: line 7: syntax error near unexpected token `else'
./functionInScript.sh: line 7: `else '
I've searched through dozens of "syntax error near unexpected token bash" and tried dozens of suggestions.
I have run dos2unix (even though I'm using Mint) on the file. I have escaped the dots in ".skandPATH" but that doesn't seem to make a difference. I have tried deleting every whitespace character and tab character. I have tried commenting out lines and executed the script in order to try and pinpoint the problem, to no avail. I'm at my wits end trying to find what's wrong here!
If you could help me... I would be most grateful.
Upvotes: 0
Views: 750
Reputation: 6480
Why not:
#!/bin/bash
testFunction() {
if ! [ -d "/home/$USER/.skandPATH/" ] ; then
mkdir /home/$USER/.skandPATH/
addedPathDir=1
fi
}
testFunction
Upvotes: 2
Reputation: 799062
You must have at least one command in a block; try :
.
Upvotes: 5