27.2.4 Inspecting entries from /etc/group

The following functions inspect entries from /etc/group using an index argument; we must obtain indexes with the functions described in Searching entries from /etc/group.

Function: mbfl_system_group_get_name GROUP_IDX
Function: mbfl_system_group_get_name_var _RV GROUP_IDX

Print to stdout the field name of the /etc/group entry at index GROUP_IDX.

The function variant _var stores the result in the variable _RV, rather than print it; Result variables.

local IDX NAME

mbfl_system_group_read
if mbfl_system_group_find_entry_by_name_var IDX root
then
    if mbfl_system_group_get_name_var NAME $IDX
    then echo "$NAME"
    fi
fi
Function: mbfl_system_group_get_passwd GROUP_IDX
Function: mbfl_system_group_get_passwd_var _RV GROUP_IDX

Print to stdout the field passwd of the /etc/group entry at index GROUP_IDX.

The function variant _var stores the result in the variable _RV, rather than print it; Result variables.

Function: mbfl_system_group_get_gid GROUP_IDX
Function: mbfl_system_group_get_gid_var _RV GROUP_IDX

Print to stdout the field gid of the /etc/group entry at index GROUP_IDX.

The function variant _var stores the result in the variable _RV, rather than print it; Result variables.

Function: mbfl_system_group_get_users GROUP_IDX
Function: mbfl_system_group_get_users_var _RV GROUP_IDX

Print to stdout the field users of the /etc/group entry at index GROUP_IDX.

The function variant _var stores the result in the variable _RV, rather than print it; Result variables.

Function: mbfl_system_group_get_users_count GROUP_IDX
Function: mbfl_system_group_get_users_count_var _RV GROUP_IDX

Print to stdout the number of user names in the list of users for the entry at index GROUP_IDX.

The function variant _var stores the result in the variable _RV, rather than print it; Result variables.

Function: mbfl_system_group_get_user_name GROUP_IDX USER_IDX
Function: mbfl_system_group_get_user_name_var _RV GROUP_IDX USER_IDX

Print to stdout the name of the user at index USER_IDX in the list of users for the entry at index GROUP_IDX.

The function variant _var stores the result in the variable _RV, rather than print it; Result variables.

local -i GROUP_IDX USER_COUNT USER_IDX
local USER_NAME

mbfl_system_group_read

if GROUP_IDX=$(mbfl_system_group_find_entry_by_name root)
then
    USER_COUNT=$(mbfl_system_group_get_users_count $GROUP_IDX)
    for ((USER_IDX=0; USER_IDX < USER_COUNT; ++USER_IDX))
    do mbfl_system_group_get_user_name $GROUP_IDX $USER_IDX
    done
fi

# Using the "_var" variants.
if mbfl_system_group_find_entry_by_name_var GROUP_IDX root
then
    mbfl_system_group_get_users_count_var USER_COUNT $GROUP_IDX
    for ((USER_IDX=0; USER_IDX < USER_COUNT; ++USER_IDX))
    do
        mbfl_system_group_get_user_name_var USER_NAME \
           $GROUP_IDX $USER_IDX
        echo "$USER_NAME"
    done
else return 1
fi

This document describes version 3.0.0-devel.9 of Marcos Bash Functions Library.