On 03/23/2010 09:31 AM, Claes Lindvall wrote:
> Very often I create a directory and then I want to move to that directory.
> I would like an option that makes it possible.
> Ex.
> # mkdir -c <dir> (-c changedir)

Thanks for the suggestion.  However, it is impossible to do as a
utility.  The notion of the current directory is a per-process notion,
with child processes inheriting their current working directory from the
parent process at the time of the fork()/exec() sequence.  There is NO
way in Unix for a child process to further influence the parents choice
of current directory, any more than there is for the parent process to
affect the child's current directory beyond its initial setting at the
fork().  Therefore, there is no way we can add a utility to coreutils to
do that.

On the other hand, this is a PERFECT use case for enhancing your
interactive shell.  For example, if you use bash, you can add this to
your ~/.bashrc, and get a mkcdir function that does exactly what you want:

mkcdir () {
  mkdir "$1" && cd "$1"
}

You can even get fancier and add logic to support passing options to mkdir.

-- 
Eric Blake   [email protected]    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to