运行bash脚本时,我收到以下错误:
./hi.sh:line 19:语法错误:意外的文件结束
这是我的代码:
#!/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
Run Code Online (Sandbox Code Playgroud)
请告诉我该怎么做.
你没有关闭你的for循环done.检查循环结构语法的手册:
for bar in 1 2 3; do
echo "$bar"
done
Run Code Online (Sandbox Code Playgroud)
另请注意,您的代码不会迭代文件的行./unauthorized_users.txt.要从文件中读取行,请改用while循环:
while IFS= read -r line; do
echo "$line"
done < your_file
Run Code Online (Sandbox Code Playgroud)