Tim Hatch

Weblog | Photos | Projects | Panoramas | About

Equivalent of os.path.abspath in bash 08 Mar, 2010

I don’t know how many times I’ve written a script that takes a directory argument, but I want to store that as an absolute path because I’ll be changing directories a lot. I had tens of lines of code to tack on $PWD with lots of conditions, but last week it finally hit me:

fullpath="$(cd "$1"; pwd)"

It will also give you the path with ../ removed.