What is this magic doing?
$(cd "${0%/*}") $(cd "${0%/*}")And yes, dirname is a way out of this. I'd do this:
"$(cd "$(dirname "$0")"; pwd)"
if I wanted the path to the script. I would also sanity-check the path by testing for the existence of some files or directories that are expected to exist under it, before trying to delete it all."the ${0%/*} pulls the path out of $0, cd's into the specified directory, then uses $PWD to figure out where that directory lives - and all this in a subshell, so we don't affect $PWD"
So for example, that would take /user/amputect/seam_setup.sh and change directories into into /user/amputect.
Since $0 is usually the name of the shellscript itself, this would be trying to obtain the directory path of the shellscript.