-
Notifications
You must be signed in to change notification settings - Fork 1
/
hello
executable file
·52 lines (46 loc) · 904 Bytes
/
hello
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
46
47
48
49
50
51
52
#! /usr/bin/env bash
#
# I'm a template for a clean and modern bash program.
# I also serve as a demo of essential bash features and good practices.
# Replace this notice with your own description.
#
# Requires bash >= 4.3.
#
set -eu -o pipefail
usage() {
cat <<EOF
Usage: $(basename "$0") [OPTIONS]
Print a greeting message.
Options:
--greeting MSG
Use another greeting message than '$default_greeting'.
--help
Print this error message and exit.
EOF
}
default_greeting="Hello"
greeting="$default_greeting"
while [[ $# -gt 0 ]]; do
case "$1" in
--greeting)
greeting="$2"
shift
;;
--help)
usage
exit 0
;;
*)
echo "Unsupported argument '$1'. Try --help." >&2
exit 1
esac
shift
done
set_username() {
username="stranger"
if [[ -v USER ]]; then
username="$USER"
fi
}
set_username
echo "$greeting, $username."