If you use bash a fair amount, you probably have some aliases set up. However, have there been times you wish you had some more control over the functionality of your alias?
Let’s examine one example: a bash alias and a bash function for extracting a file.
With an alias, we can easily abstract out the complicated
tar command to simply
Now we can type
extract file.tar.gz or
extract file.tgz and the command will extract the file. We can even specify output directories!
But what if we can’t rely on our downloaded file to have
.tgz extensions? Well in that case, a function for
extract makes more sense!
Now we can call
extract without worrying about our file extension! We can just trust that the function will do exactly what it’s meant to.
So how can I start using bash functions?
First, import a file called
.bash_functions in your
Now you can either download my
.zsh_fns file (bash functions for
zsh) as a starting point, or create your own at
Note: You must restart terminal or type
source .bashrc in your terminal to start using the new bash functions