Reputation: 27
When running a bash script i get the following error:
./hi.sh: line 19: syntax error: unexpected end of file
Here is my code:
#!/bin/bash
#Remove unauthorized users
for line in ./unauthorized_users.txt; do
sudo userdel $line -y
sudo rm -rf "/home/$line" -y
#Remove unauthorized packages
for line in ./bad_packs.txt; do
sudo apt-get remove $line -y
sudo apt-get purge $line -y
Please advise me on what to do.
Upvotes: 1
Views: 871
Reputation: 7499
You are not closing your for
loop with done
. Check manual for looping constructs' syntax:
for bar in 1 2 3; do
echo "$bar"
done
Also note that your code won't iterate over lines of the file ./unauthorized_users.txt
. To read lines from a file, use while
loop instead :
while IFS= read -r line; do
echo "$line"
done < your_file
Upvotes: 5
Reputation: 363
Both 'for' loops need closing 'done's
for line in file; do
echo "$line" # do some stuff
done
Other bash constructs (if, case, etc.) need closing statements as well
Upvotes: 1