sh mkcd命令 - 如何使用mkdir和cd一步创建目录

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh mkcd命令 - 如何使用mkdir和cd一步创建目录相关的知识,希望对你有一定的参考价值。

#
#   mkcd command
#   This is an improvised version of the mkcd command at http://superuser.com/questions/152794/is-there-a-shortcut-to-mkdir-foo-and-immediately-cd-into-it
#   This function has to be added to the ~/.bashrc file
#   After that you can run command like: mkdir abc, mkdir -p one/two/three
#
function mkcd {
  last=$(eval "echo \$$#")
  if [ ! -n "$last" ]; then
    echo "Enter a directory name"
  elif [ -d $last ]; then
    echo "\`$last' already exists"
  else
    mkdir $@ && cd $last
  fi
}

以上是关于sh mkcd命令 - 如何使用mkdir和cd一步创建目录的主要内容,如果未能解决你的问题,请参考以下文章