Skip to content

Instantly share code, notes, and snippets.

@rehnen
Last active December 13, 2015 09:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rehnen/34236d6ff270ccaa74b6 to your computer and use it in GitHub Desktop.
Save rehnen/34236d6ff270ccaa74b6 to your computer and use it in GitHub Desktop.
Mkdir and cd

#mkdir, like it was meant to be!#

##Here is how you do it##

Open up an editor and create a script file, in my case "mkdirn.sh". And inside the file we will put the following:

mkdir $1
cd $1

The $1 refers to what ever we put after our initial command in the case of mkdir abc $1 refers to abc. Now if we run our script ./mkdirn mydir we will notice that we will in fact create the directory named "mydir", but we will not be relocated to "mydir". The cd command is indeed executed, but as soon as the script exits we will be back where we started. This is because of the fact that the script is not being executed in a subshell that is on a different process. To run it from our process, just type: . ./mkdirn mydir and notice that there is a space between the dots.

Now to make it system wide we'll use an alias. Note that /mkdirn.sh is the path to my script, "" is the home directory of the current user, a shorthand for "/home/username". And again notice that there is a space after the dot.

alias mkdirn='. ~/mkdirn.sh'

Written with StackEdit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment