How an bash script is able to discover self path (path in which it is placed)?

Here is one way:

# cat /path/to/script

DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
echo $DIR
# /path/to/script

/path/to