-1

How can I create a reliable alias or function that let me create and cd into one directory?

I tried the following, but, as an example can't create directories with spaces.

mcd () {
        mkdir $1 && cd $1
}
jherran
  • 3,939

1 Answers1

4

Always put double quotes between variable in bash to avoid space problem ;)

mcd () {
  mkdir "$1" && cd "$1"
}
AlexeyGy
  • 101