Automated wrapper shell improvements - possible better way to find APP_HOME

Code reviewed something I thought was written by someone, thought it may be useful to send this your way. To summarize, it looks like gradlew maybe goes to some length to find the absolute path for APP_HOME based on $1. If that is a correct understanding, then this code might be simpler:

APP_HOME=$(cd $(echo $1); pwd)

In more detail:
DanVanAtta commented on the diff an hour ago
View full changes gradlew
((214 lines not shown))
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h “$PRG” ] ; do

  • ls=ls -ld "$PRG"
  • link=expr "$ls" : '.*-> \(.*\)$'
  • if expr “$link” : ‘/.*’ > /dev/null; then
  •    PRG="$link"
    
  • else
  •    PRG=`dirname "$PRG"`"/$link"
    
  • fi
    +done
    +SAVED="pwd"
    +cd “dirname \"$PRG\"/” >&-
    +APP_HOME="pwd -P"
    @DanVanAtta Collaborator
    DanVanAtta added a note an hour ago
    The above might be overkill for getting the absolute path of $1 (that is what we are trying to do?).

If so, cd to $1 in a subshell and then run “pwd”. You’ll get the output, and since the cd was done in subshell it doesn’t effect the path of the current shell. So ie:

APP_HOME=$(cd $(echo $1); pwd)