'Getting 'end of file' error in my bash script. What am I missing?
I have a large amount of files that I have just recovered from a wiped HDD and I would like to sort them into folders that are named after the files' "created" timestamp. In the process of writing this (seemingly) simple script, I can't figure out why I get an "Unexpected End of file Error"...
cd ~/R1c/scripts/files
for file in *.{jpg,jpeg,png,gif,mp4,avi,txt}
do
year=$(stat file | cut -d " " -f20 | tr -d '"')
month=$(stat file | cut -d " " -f17 | tr -d '"')
STOREDIR=${year}_${month}
if [ -d ${STOREDIR} ]; then
mv ${file} ${STOREDIR}
elif
mkdir ${STOREDIR}
mv ${file} ${STOREDIR}
end if
end for
This is run on macOS if that's important :)
Solution 1:[1]
Simply put, because there's no comparison statement after the elif (which should be an else clause) bash then interprets the whole thing wrong and complains about the fi statement instead of actually pointing out the fact that there's an elif without an else.
Thus, changing the elif to else did the trick :)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
