前安全检查我有一个脚本,它确实需要在一个特定的文件夹
我想使这个尽可能安全的RM -fr。我在下面开始了这个脚本,但我想知道是否还有其他东西我错过了。
folder=""
if [[ ! -d "$folder" ]]; then
echo "Error: is not a folder"
elif [[ "$folder" == "/" ]]; then
echo "Error: folder points to root"
elif [[ "$folder" == "../"* ]]; then
echo "Error: folder start with ../"
elif [[ "$folder" == *"/.."* ]]; then
echo "Error: folder contains /.."
elif [[ "$folder" == *"/*"* ]]; then
echo "Error: folder ends with /*"
else
rm -fr "$folder"
fi
更新:添加了检查“/”
也可能检查'/'? – codeforester
谢谢我更新了代码! – Zurd
是位于给定用户下的所有文件夹..例如〜/ home/jsmith? – zee