views:

117

answers:

1

Trying to create:

alias mcd="mkdir $1; cd $1"

Getting:

$ mcd foo
usage: mkdir [-pv] [-m mode] directory ...
-bash: foo: command not found

What am I doing wrong?

+7  A: 

turn it into a function:

function mcd()
{
  test -e $1 || mkdir $1; cd $1;
}
just somebody
Could have been a shell script too? Named as a file mcd with no extension? How is a function different or better?
talkaboutquality
It wouldn't work as a shell script, because the script would run in a subshell. In order for the cd to have the intended effect, it has to run in the caller's shell, not a subshell.
Gordon Davisson