Use $PWD for cwd before attempting getcwd() .