| #!/bin/bash |
| |
| process_u() { |
| if [ ! -z "${2##*[!0-9]*}" ]; then |
| |
| echo "user($1) = $2" |
| echo "group($1) = $2" |
| elif [[ $2 == *:* ]]; then |
| |
| uid=$(echo $2 | cut -d':' -f1 -) |
| group=$(echo $2 | cut -d':' -f2 -) |
| if [ ! -z "${group##*[!0-9]*}" ]; then |
| |
| echo "user($1) = ${uid}" |
| echo "group($1) = ${group}" |
| else |
| |
| echo "user($1) = ${uid}" |
| echo "group(${group})" |
| fi |
| else |
| |
| echo "user($1)" |
| echo "group($1)" |
| fi |
| } |
| |
| process_g() { |
| if [ ! -z "${2##*[!0-9]*}" ]; then |
| |
| echo "group($1) = $2" |
| else |
| |
| echo "group($1)" |
| fi |
| } |
| |
| parse() { |
| while read line; do |
| [ "${line:0:1}" = '#' -o "${line:0:1}" = ';' ] && continue |
| line="${line## *}" |
| [ -z "$line" ] && continue |
| set -- $line |
| case "$1" in |
| ('u') |
| process_u "$2" "$3" |
| ;; |
| ('g') |
| process_g "$2" "$3" |
| ;; |
| ('m') |
| echo "user($2)" |
| echo "group($3)" |
| ;; |
| esac |
| done |
| } |
| |
| while read fn; do |
| parse < "$fn" |
| done |