-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdiamond_better.sh
More file actions
57 lines (46 loc) · 932 Bytes
/
diamond_better.sh
File metadata and controls
57 lines (46 loc) · 932 Bytes
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
#!/bin/bash
#Diamond script
if [ $1 ]
then number=$1
else echo -n "Enter number: "
read number
fi
limit=$((number*2+1))
si=$((0-number))
i=0
#space input test
charlimit=${#number}
charcount=0
for ((a=1; a<=$limit; a++))
do
i=$si
for ((b=1; b<=$limit; b++))
do
var=$i
#space input test
if [ $var -lt 0 ]
then testvar=0
else testvar=$var
fi
charcount=${#testvar}
chardif=$((charlimit-charcount))
for ((c=0; c<chardif; c++))
do
echo -n " "
done
#end space input test
if [ $var -ge 0 ]
then echo -n $var
else echo -n " "
fi
if [ $b -gt $number ]
then i=$((i-1))
else i=$((i+1))
fi
done
echo -ne "\n"
if [ $a -gt $number ]
then si=$((si-1))
else si=$((si+1))
fi
done