-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathif.sh
More file actions
executable file
·107 lines (100 loc) · 1.8 KB
/
if.sh
File metadata and controls
executable file
·107 lines (100 loc) · 1.8 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/bin/bash
RESTORE=$'\033[0m'
RED=$'\033[00;31m'
GREEN=$'\033[00;32m'
YELLOW=$'\033[00;33m'
BLUE=$'\033[00;34m'
PURPLE=$'\033[00;35m'
CYAN=$'\033[00;36m'
LIGHTGRAY=$'\033[00;37m'
LRED=$'\033[01;31m'
LGREEN=$'\033[01;32m'
LYELLOW=$'\033[01;33m'
LBLUE=$'\033[01;34m'
LPURPLE=$'\033[01;35m'
LCYAN=$'\033[01;36m'
WHITE=$'\033[01;37m'
echo "${GREEN}==============="
echo "##### IF ######"
echo "===============${RESTORE}"
echo "${YELLOW}Usage:${RESTORE}"
cat <<EOF
if [ condition-true ]
then
command 1
command 2
...
fi
EOF
echo "${BLUE}Example:${RESTORE}"
out='MY_SHELL="bash"
if [ "$MY_SHELL" = "bash" ]
then
echo "You seem to like the bash shell."
fi'
echo "${out}"
echo "${GREEN}TEST:${RESTORE}"
eval "${out}"
echo
echo "${GREEN}=================="
echo "### IF # ELSE ####"
echo "==================${RESTORE}"
echo "${YELLOW}Usage:${RESTORE}"
cat <<EOF
if [ condition-true ]
then
command 1
command 2
...
else
command 3
command 4
...
fi
EOF
echo "${BLUE}Example:${RESTORE}"
out='MY_SHELL="zsh"
if [ "$MY_SHELL" = "bash" ]; then
echo "You seem to like the bash shell."
else
echo "You do not seem to like the bash shell."
fi'
echo "${out}"
echo "${GREEN}TEST:${RESTORE}"
eval "${out}"
echo
echo "${GREEN}=================="
echo "### IF # ELIF ####"
echo "==================${RESTORE}"
echo "${YELLOW}Usage:${RESTORE}"
cat <<EOF
if [ condition-true ]
then
command 1
command 2
...
elif [ condition-true ]
then
command 3
command 4
...
else
command 5
command 6
...
fi
EOF
echo "${BLUE}Example:${RESTORE}"
out='MY_SHELL="zsh"
if [ "$MY_SHELL" = "bash" ]
then
echo "You seem to like the bash shell."
elif [ "$MY_SHELL" = "zsh" ]
then
echo "You seem to like the zsh shell."
else
echo "You do not seem to like the bash or zsh shells."
fi'
echo "${out}"
echo "${GREEN}TEST:${RESTORE}"
eval "${out}"