-
Notifications
You must be signed in to change notification settings - Fork 0
/
randomgen.sh
145 lines (140 loc) · 3.84 KB
/
randomgen.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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/usr/bin/bash
numb=$(($2-1))
lchars=$'abcdefghijklmnopqrstuvwxyz'
uchars=$'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
nchars=$'1234567890'
schars=$'0=+-\'`"[]{}()<>;:,./~!@#$%^&*_|?\\'
lowerc=false
upperc=false
num=false
special=false
while getopts luns: flag
do
case "${flag}" in
l) lowerc=true;;
u) upperc=true;;
n) num=true;;
s) special=true;;
esac
done
if [ "$lowerc" = true ] && [ "$upperc" = false ] && [ "$num" = false ] && [ "$special" = false ]; then
for (( i = 0; i <= $numb; i++ ))
do
echo -n "${lchars:RANDOM%${#lchars}:1}"
done
echo \n
exit 0
elif [ "$lowerc" = false ] && [ "$upperc" = true ] && [ "$num" = false ] && [ "$special" = false ]; then
for (( i = 0; i <= $numb; i++ ))
do
echo -n "${uchars:RANDOM%${#uchars}:1}"
done
echo \n
exit 0
elif [ "$lowerc" = false ] && [ "$upperc" = false ] && [ "$num" = true ] && [ "$special" = false ]; then
for (( i = 0; i <= $numb; i++ ))
do
echo -n "${nchars:RANDOM%${#nchars}:1}"
done
echo \n
exit 0
elif [ "$lowerc" = false ] && [ "$upperc" = false ] && [ "$num" = false ] && [ "$special" = true ]; then
for (( i = 0; i <= $numb; i++ ))
do
echo -n "${schars:RANDOM%${#schars}:1}"
done
echo \n
exit 0
elif [ "$lowerc" = true ] && [ "$upperc" = true ] && [ "$num" = false ] && [ "$special" = false ]; then
for (( i = 0; i <= $numb; i++ ))
do
master=$lchars$uchars
echo -n "${master:RANDOM%${#master}:1}"
done
echo \n
exit 0
elif [ "$lowerc" = true ] && [ "$upperc" = false ] && [ "$num" = true ] && [ "$special" = false ]; then
for (( i = 0; i <= $numb; i++ ))
do
master=$lchars$nchars
echo -n "${master:RANDOM%${#master}:1}"
done
echo \n
exit 0
elif [ "$lowerc" = true ] && [ "$upperc" = false ] && [ "$num" = false ] && [ "$special" = true ]; then
for (( i = 0; i <= $numb; i++ ))
do
master=$lchars$schars
echo -n "${master:RANDOM%${#master}:1}"
done
echo \n
exit 0
elif [ "$lowerc" = false ] && [ "$upperc" = true ] && [ "$num" = true ] && [ "$special" = false ]; then
for (( i = 0; i <= $numb; i++ ))
do
master=$uchars$nchars
echo -n "${master:RANDOM%${#master}:1}"
done
echo \n
exit 0
elif [ "$lowerc" = false ] && [ "$upperc" = true ] && [ "$num" = false ] && [ "$special" = true ]; then
for (( i = 0; i <= $numb; i++ ))
do
master=$uchars$schars
echo -n "${master:RANDOM%${#master}:1}"
done
echo \n
exit 0
elif [ "$lowerc" = false ] && [ "$upperc" = false ] && [ "$num" = true ] && [ "$special" = true ]; then
for (( i = 0; i <= $numb; i++ ))
do
master=$nchars$schars
echo -n "${master:RANDOM%${#master}:1}"
done
echo \n
exit 0
elif [ "$lowerc" = true ] && [ "$upperc" = true ] && [ "$num" = true ] && [ "$special" = false ]; then
for (( i = 0; i <= $numb; i++ ))
do
master=$lchars$uchars$nchars
echo -n "${master:RANDOM%${#master}:1}"
done
echo \n
exit 0
elif [ "$lowerc" = true ] && [ "$upperc" = true ] && [ "$num" = false ] && [ "$special" = true ]; then
for (( i = 0; i <= $numb; i++ ))
do
master=$lchars$uchars$schars
echo -n "${master:RANDOM%${#master}:1}"
done
echo \n
exit 0
elif [ "$lowerc" = true ] && [ "$upperc" = false ] && [ "$num" = true ] && [ "$special" = true ]; then
for (( i = 0; i <= $numb; i++ ))
do
master=$lchars$nchars$schars
echo -n "${master:RANDOM%${#master}:1}"
done
echo \n
exit 0
elif [ "$lowerc" = false ] && [ "$upperc" = true ] && [ "$num" = true ] && [ "$special" = true ]; then
for (( i = 0; i <= $numb; i++ ))
do
master=$uchars$nchars$schars
echo -n "${master:RANDOM%${#master}:1}"
done
echo \n
exit 0
elif [ "$lowerc" = true ] && [ "$upperc" = true ] && [ "$num" = true ] && [ "$special" = true ]; then
for (( i = 0; i <= $numb; i++ ))
do
master=$lchars$uchars$nchars$schars
echo -n "${master:RANDOM%${#master}:1}"
done
echo \n
exit 0
else
echo 'options: {l}ower-case letters, {u}pper-case letters, {n}umbers, {s}pecial characters'
exit 1
fi
exit