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.

Tags: ,

One Response to “Bash equivalent for PHP realpath()”

  1. CodeWord: Apokalyptik » Blog Archive » This deserves some link love Says:

    [...] bogged a piece of advice that I have him which I got from Barry… and if you want to know how to get the true absolute path to the real location of the current script is from inside of it (like phps realpath and __FILE__) I suggest you check it out Subscribe to the comments for this [...]

Leave a Reply