-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathluser-demo03.sh
executable file
·43 lines (34 loc) · 970 Bytes
/
luser-demo03.sh
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
36
37
38
39
40
41
42
43
#!/bin/bash
# Display the UID and username of the user executing this script.
# Display if the user is the gr3yhatt3r user or not.
# Display the UID
echo "Your UID is $(id -u)."
# Only display if the UID does NOT match 1000.
UID_TO_TEST_FOR='1000'
if [[ "${UID}" -ne "${UID_TO_TEST_FOR}" ]]
then
echo "Your UID does not match ${UID_TO_TEST_FOR}"
exit 1
fi
# Dsipaly the username.
USER_NAME=$(id -un)
# Test if the command succeeded.
if [[ "${?}" -ne 0 ]]
then
echo 'The id command did not execute successfully.'
exit 1
fi
echo "Your username is ${USER_NAME}"
# You can use a string test conditional.
USER_NAME_TO_TEST_FOR='gr3yhatt3r'
if [[ "${USER_NAME}" = "${USER_NAME_TO_TEST_FOR}" ]]
then
echo "Your username matches ${USER_NAME_TO_TEST_FOR}."
fi
# Test for the != (not equal) for the string.
if [[ "${USER_NAME}" != "${USER_NAME_TO_TEST_FOR}" ]]
then
echo "Your username does not match ${USER_NAME_TO_TEST_FOR}"
exit 1
fi
exit 0