-
Notifications
You must be signed in to change notification settings - Fork 4
/
seq.sh
58 lines (54 loc) · 785 Bytes
/
seq.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
#!/usr/bin/ksh
start=1
end=1
step=1
case $# in
0)
echo Usage: $0 '[Start [Step]] End'
exit 0
;;
1)
end=$1
;;
2)
start=$1
end=$2
;;
3)
start=$1
step=$2
end=$3
;;
esac
# quick & dirty validations
if [ $step -eq 0 ]
then
exit 1
fi
if [ $step -gt 0 ]
then
if [ $start -gt $end ]
then
exit 2
fi
else
if [ $start -lt $end ]
then
exit 3
fi
fi
i=$start
if [ $step -gt 0 ]
then
while [ $i -le $end ]
do
printf "%d\n" $i
i=$(( i + step ))
done
else
while [ $i -ge $end ]
do
printf "%d\n" $i
i=$(( i + step ))
done
fi