Bash Functions: A more powerful Alias

aarohmankad

Aaroh Mankad

Posted on December 24, 2017

Bash Functions: A more powerful Alias

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 extract.

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 .tar.gz / .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 .bashrc.

Now you can either download my .zsh_fns file (bash functions for zsh) as a starting point, or create your own at ~/.bash_functions!

Note: You must restart terminal or type source .bashrc in your terminal to start using the new bash functions

💖 💪 🙅 🚩
aarohmankad
Aaroh Mankad

Posted on December 24, 2017

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Bash Functions: A more powerful Alias
terminal Bash Functions: A more powerful Alias

December 24, 2017