# Calculate the name for ripping
base="$1"
last="$(find . -maxdepth 1 -type d -name "${base}*" | sort -n | tail -n 1)"
-if [ -z "$last" ]; then
- num="1"
-elif [ -n "$2" ]; then
+if [ -n "$2" ]; then
num="$2"
+elif [ -z "$last" ]; then
+ num="1"
else
num="${last##./${base}}"
num="$(($num + 1))"