Bash (using word designators):
/tmp/bug$ mkdir "some dir"
/tmp/bug$ cd !$
cd "some dir"
/tmp/bug/some dir$
!$
expands to the last argument of the previous line in the history. If you have parameters in between, then you can use !:1
for the first argument, !:2
forthe second argument, etc.
From bash(1):
Event Designators
An event designator is a reference to a command line entry in the
history list. Unless the reference is absolute, events are relative
to the current position in the history list.
!
Start a history substitution, except when followed by a blank,
newline, carriage return, =
or (
(when the extglob shell option is
enabled using the shopt builtin).
[..]
Word Designators
Word designators are used to select desired words from the event.
A :
separates the event specification from the word designator. [..]
[..]
n The n-th word.
^
The first argument. That is, word 1.
$
The last word. This is usually the last argument, but will
expand to the zeroth word if there is only one word in the line.