Alternatively, you can add ':p' to the third line. This will print out the command rather than executing it. Additionally, it's also added to your bash history, so you can add it by pressing the up arrow.
$ chmod 755 foo
$ cd !$:p
cd foo
$ cd foo
There are some similar "tricks" here: