First, do not just copy paste and execute some code that you do not understand, especially if it involves deleting files/directories.
Second, do not
parse the output from ls.
Third, your example lacks important information.
What is the value of $APPVER? How does it get assigned? What does the directory structure look like? What do you mean by "last" two directories? Directories at that are at depth < 2? Or the last two directories that are listed by
ls?