0

I am stuck on trying to create an alias that will cd back a directory, make a new directory with a given name and then cd into it. Here is what I have so far:

alias cdmk="cd .. | mkdir '$1' | cd '$1'"

I just want to be able to type cdmk and then the name of the new directory I want to create and cd into.

Any help you can give would be much appreciated!

Jack
  • 11
  • 1
  • Use a function. This has been answered [http://stackoverflow.com/questions/941338/how-to-pass-command-line-arguments-to-a-shell-alia](here). – Neil Masson Dec 03 '15 at 14:32

2 Answers2

0

Just use a function:

cdmk() {
    local new_dir="../$1"
    mkdir "$new_dir" && cd "$new_dir"
}

Using && means that if creating the directory fails, changing to it is not attempted.

Tom Fenech
  • 72,334
  • 12
  • 107
  • 141
0

You need a function :

cdmk () { cd ..;mkdir "${1}";cd "${1}"; }
emesika
  • 73
  • 1
  • 4