Files & Directories

Create a directory if it doesn’t exist

if [[ ! -d ~/bin ]]
then
  mkdir ~/bin
fi

Get script parent directory

parentDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
echo "$parentDir"

Get full path of a file

Note: Also the actual file of a symbolic link

filePath="$(readlink $filePath)"
filePath="$(readlink ~/dir)"