Add a Function to .bashrc Profile in Linux

A Linux .bashrc profile is a file that is used to configure the system’s Bash shell environment.

Linux users can edit this file with any text editor, or just open it for editing in their favourite terminal emulator (such as Gnome Terminal on Linux). Doing so will show some default commands and functions for Linux users to include in their custom configuration. One of these functions is called alias which allows you to create an alternative name for a command.

Add Function

To add a function to a Bash profile file, edit your .bashrc file located under your home folder.

In the below example, I’m adding a function that activates a python virtual environment when I enter start-ansible.

function start-ansible() {
    source ~/virtualenv/ansible/bin/activate
}

Below you can see a screenshot of a .bashrc profile.

Leave a comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.