Wednesday, March 27, 2013

Sharing Bash Functions

Intro

In order to share a bash function between all logins you can insert the function in /etc/bash.bashrc and source it in /etc/profile.

Example

In order to share a members function that all users can execute to find which users belong to a particular unix user group, then do the following:

/etc/bash.bashrc


members()
{
   cat /etc/group | grep --regex "^$1:.*" | awk -F: '{print $4}'
}

/etc/profile

# ...
source /etc/bash.bashrc


Now, when any user logs in they will be able to run members like this:

$ members users
alice,bob,cindy




Sponsor Ads


1 comment:

  1. Techsaga is the best Mobile apps development company Get a mobile app for your business today, to connect with a wider audience. Believing and nurturing, Innovation, Advancement and Growth introducing Technology and much more that we do in our routine to bring awesomeness to every product. We never settle until we achieve best.

    ReplyDelete