Bash – Creating a simple function

This guide will show how to create a simple function that will change directory while in a bash terminal (ie vagrant box, ubuntu, etc).

First of all we need to edit our bashrc file: I will use VIM

vim ~/.bashrc

Now in the bashrc file we can create our function, it is very similar to other languages, see my example below

test() { cd ~/sites/test-project ; }

So no matter what folder I go to I can type “test” to open up my test-project. Again like any change in bash we need to reload our bash config to apply changes.

source ~/.bashrc

Leave a Reply

Your email address will not be published. Required fields are marked *