添加 完善latest参数行为与无参默认行为

This commit is contained in:
2026-04-12 16:41:14 +08:00
parent 863fee96f1
commit 6f57abda16
5 changed files with 152 additions and 14 deletions

27
remove
View File

@@ -1,2 +1,27 @@
#!/bin/bash
rm /fr ./$1
# Version Check
TEXT=$(
curl -s https://terraria.wiki.gg/wiki/Desktop_version_history | tr '\n' ' ' | grep -oP '(?<=<tbody>).*?(?=</tbody>)'
)
ALL_VERSIONS=$(echo "$TEXT" | grep -oP '[0-9]+\.[0-9]+(\.[0-9]+)?+(\.[0-9]+)?')
VERSION=$(echo "$ALL_VERSIONS" | head -n1)
VERSION_NO_DOT=$(echo "$VERSION" | tr -d '.')
if [[ $1 == 'latest' ]]; then
echo "Latest version: $VERSION"
VERSION=$VERSION_NO_DOT
elif [[ -n $1 ]]; then
if echo "$ALL_VERSIONS" | tr -d '.' | grep -q "^$1$"; then
VERSION=$1
echo "Selected version: $VERSION"
else
echo "Error: version '$1' not found in version history."
exit 1
fi
else
echo "Latest version: $VERSION"
VERSION=$VERSION_NO_DOT
fi
# Remove
rm /fr ./$VERSION