-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaccount
More file actions
executable file
·35 lines (30 loc) · 1.04 KB
/
account
File metadata and controls
executable file
·35 lines (30 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/bash
######################################################################
# Author: jrjbear@gmail.com
# Date: Thu Jan 30 12:07:38 2014
# File: account
#
# Usage: account userid
# Description: Print account information according to the given userid
######################################################################
# Use `read' instead of `for' loop to get fields because they may
# contain blanks in username. Use process substitution instead of
# pipes to while since the latter will run in a subshell (which
# hides the variable inside `while').
while read line; do
user="${line%%:*}"
name="${line##*:}"
user_uid="${line%:*}"
uid=${user_uid#*:}
acc[${uid}]="${user}:${name}"
done < <(cut -f1,3,5 -d: /etc/passwd)
if ! echo $1 | grep '^[0-9]\+$' > /dev/null; then
echo "Usage: $0 userid" >&2
exit 1
fi
if [[ -z "${acc[$1]}" ]]; then
echo "User ID $1 not found" >&2
exit 1
fi
echo "User ID $1 is ${acc[$1]%:*}, whose full name is ${acc[$1]#*:}"
echo "There are currently ${#acc[@]} user accounts on the system"