这是我的第一个 bash 脚本。我需要从当前文件夹中删除所有 .html 文件。
我有这个:
#!/bin/bash
HTML_FILE_COUNT=$(find . -maxdepth 1 -type f -name "*.html" | wc -l)
echo "Remove $HTML_FILE_COUNT file(s) with .html extension (yes / no)?"
echo -n "Answer: "
read ANSWER
if [ [$ANSWER = "yes"] ]; then
echo "$(find . -maxdepth 1 -type f -name "*.html" -delete)"
echo "Files have been removed!"
elif [ [$ANSWER = "no"] ]; then
echo "No file has been removed!"
else
echo "Unknown command!"
fi
但是,该if else
块仅返回Unknown command
.我在这里缺少什么?
答案1
您需要在[ ]
括号和变量/字符串之间有空格。
if [[ $ANSWER = "yes" ]]; then
...
elif [[ $ANSWER = "no" ]]; then