这是我的第一个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
。我在这里想念什么?
您需要在[ ]
方括号和变量/字符串之间加白点。
if [[ $ANSWER = "yes" ]]; then
...
elif [[ $ANSWER = "no" ]]; then
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句