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


No comments:

Post a Comment