This question already has an answer here:
I was trying to define an alias that helps me to cd to the directory that is created most recently, and I'm using the following in my .bashrc:
alias cdlatest="latestdir=$(ls -td -- */|head -n 1); cd $latestdir"
But this alias only works once. If I change to a new directoy, it still tries to cd to the last directory. It seems becaue the variable
$(ls -td -- */|head -n 1) is only evaluated once from the start. How to fix this?