Bash equivalent for PHP realpath()

For all you PHP hackers trying to write a BASH script and looking for an equivalent for PHP’s realpath function, try readlink. It can expand symbolic links and resolve relative paths like “./” and “../”. In a shell script, try this:

MY_PATH=$(readlink -f $0)

Thanks to Barry.