The first command,
creates directories specified by the arguments supplied to the function. The "$@" ensures that names containing spaces will be treated correctly. The other command,
cd's to the last directory specified. The entire point here is to get the last argument of the function. The example uses
eval to make the command be evaluated twice. So, during the first pass \" will become ", \$ will become $ and $# will be replaced by its value. Then the result will be executed as a command.
So, asuming that the function is called as, for example:
Directories
a,
b,
c and
d will be created. Then,
eval will force the other part to be evaluated. So,
will become
because the function was called with 4 arguments.
However, keep in mind that
eval is a tool that is
best left alone.
Instead, I would write
Code:
mkdircd () { mkdir -p "$@" && cd "${!#}"; }
which IMHO is much nicer.
Also, please note that a function definition in
bash is either
Code:
function foo { ... }
or
Using of
Code:
function foo() { ... }
is not recommended.