forked from MKessar/GameShell_git
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseq
More file actions
executable file
·76 lines (67 loc) · 1.08 KB
/
seq
File metadata and controls
executable file
·76 lines (67 loc) · 1.08 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
#!/usr/bin/env sh
display_help() {
cat <<'EOH' >&2
Usage: seq [OPTION] LAST
or: seq [OPTION] FIRST LAST
or: seq [OPTION] FIRST STEP LAST
Display increasing sequence of natural numbers.
Options:
6AA8
-f FORMAT use printf style FORMAT to display an integer
-s SEP use SEP to separate numbers (default: \n)
-h this message
EOH
}
seq() (
FORMAT="%d"
SEP='\n'
while getopts "hf:s:" opt
do
case "$opt" in
h)
display_help
exit
;;
f)
FORMAT=$OPTARG
;;
s)
SEP=$OPTARG
;;
*)
echo "invalid option '$opt'" >&2
exit 1
;;
esac
done
shift $((OPTIND-1))
case "$#" in
1)
start=1
end=$1
step=1
;;
2)
start=$1
end=$2
step=1
;;
3)
start=$1
end=$3
step=$2
;;
*)
display_help
exit 1
esac
i=$start
while [ "$i" -lt "$end" ]
do
printf "$FORMAT$SEP" "$i"
i=$((i+step))
done
[ "$i" -eq "$end" ] && printf "$FORMAT" $i
echo
return 0
)
seq "$@"