replace pushd/popd commands

as they are not avail on all distributions (eg ubuntu)
Fixes #1232