-
Notifications
You must be signed in to change notification settings - Fork 1
/
multiple_entry.sh
executable file
·45 lines (37 loc) · 983 Bytes
/
multiple_entry.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
44
45
#!/bin/bash
# WARNING!
# THIS TECHNIQUE COULD EXPOSE A PRIVILEGE ESCALATION IF THE SCRIPT RUNS IN A
# PRIVILEGED CONTEXT, BUT CAN BE INVOKED FROM AN UNPRIVILEGED CONTEXT. FOR
# EXAMPLE, USING SUDO OR A SETUID BIT.
# This file demonstrates a script with multiple entry points.
# Try the following invocations:
# $ ./multiple_entry.sh funcOne
# $ ./multiple_entry.sh funcTwo 1 2 "3 4" 5
funcOne() {
echo "Running funcOne"
}
funcTwo() {
echo "Running funcTwo"
local count=1
for arg in "${@}"; do
echo "[${count}]: ${arg}"
(( count += 1 ))
done
}
# Handle mistyped commands in Bash >= 4.0
command_not_found_handle() {
echo "The following command is not valid: \"${1}\""
exit 1
}
if [ "${BASH_SOURCE}" = "${0}" ]; then
if [ -n "${1}" ]; then
CALL_FUNC="${1}"
# Handle mistyped commands in Bash < 4.0
if [ "$(type -t "${CALL_FUNC}")" != "function" ]; then
echo "${CALL_FUNC}: Function not found." >&2
exit 1
fi
shift
"${CALL_FUNC}" "${@}"
fi
fi