-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·37 lines (31 loc) · 839 Bytes
/
test.sh
File metadata and controls
executable file
·37 lines (31 loc) · 839 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
revline() {
echo "$1" | tr " " "\n" | sed -r 's/^ $//' > words.txt
declare -a arr
count=0
for ln in `cat words.txt`; do
count=$((count + 1))
arr[count]="$ln"
done
result=""
for ((i = $count; i >= 0; i --)); do
result=$result" "$(revword "${arr[i]}")
echo "$result" | sed -r 's/^ //g;s/ $//g'
done
return 0
}
revword()
{
echo "$1" | sed -r 's/./&\n/g' > temp.txt
declare -a arr
count=0
for ln in `cat temp.txt`; do
arr[count]="$ln"
count=$((count + 1))
done
result=""
for((i = $count; i >= 0; i --)); do
result=$result$(echo "${arr[i]}")
done
echo "$result"
}
revline "hi there cs5521"