In case you need to get the absolute path to the folder in which a bash script exists (e.g. when you need to refer to a relative binary), you can do it like this:
#!/usr/bin/env bashSCRIPTPATH="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"echo $SCRIPTPATH
So, if you run the script, you will get:
You can then use it to easily refer to a relative binary or file in a reliable way. We use this to create a script which uses
xcodebuild but applies
xcbeautify to it's output. As we are using a custom build of
xcbeautify and have it in the same folder as the script, this trick becomes really handy:
#!/usr/bin/env bashSCRIPTPATH="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"PRETTIER=$SCRIPTPATH/xcbeautifyset -o pipefail && xcodebuild "$@" | $PRETTIER --disable-colored-outputexit $?