Using the pushd command in your home directory give you ~, but when I try to access it with
cd $(dir +1), it gives an error cd: ~: No such file or directory, after some research, (please correct me if I'm wrong) I think the error is that ~ is not used at the start of line, and the ~ sign is not changed into /home/myname.

Is there any way to fix this?

1 Answer 1


Use dirs -l +1 to print the full path to the directory, with no ~ abbreviation. Tilde expansion only happens when it's typed explicitly, not in the output of a command.

cd $(dirs -l +1)

Alternatively, use zsh, where you can simply write

cd +1

But even in bash you can just write

pushd +1

which has almost the same effect (it leaves the stack in a different order).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .