This repository was archived by the owner on Mar 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.sh
More file actions
executable file
·61 lines (43 loc) · 1.34 KB
/
example.sh
File metadata and controls
executable file
·61 lines (43 loc) · 1.34 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
#!/bin/bash
source ./stack.sh || { echo "./stack.sh not found"; exit 1; }
echo "First, create a snapshot of the current environment to detect"
echo "possible memory leaks after we end up working with our stack."
env="$(set | grep -v '^_=')"
echo
echo "Ok, let's create some stack, shall we?"
stack:new s
${s}.size
@out size = 1
echo "Size of the new stack is '${size}', but also '$(${s}.size -)'."
unset size
echo "Now push some values onto it."
${s}.push value{1..20}
echo "Size of the filled stack is '$(${s}.size -)'."
${s}.top
@out top = 1
echo "Top value is '${top}', but also '$(${s}.top -)."
unset top
echo "Now pop out the values."
echo
while (( $(${s}.size -) )) ; do
${s}.pop -
${s}.pop
@out val = 1
echo "${val}"
done
unset val
echo
echo "Size of the emptied stack is $(${s}.size -)."
echo "Now destroy the stack."
${s}.destroy
echo
echo "And try to push some value again."
${s}.push "Ouch" 2>/dev/null
(( $? == 127 )) && echo " > Error: Command was not found. <" || echo "This stack implementation is a broken crap, you knew it."
echo 'Delete the variable holding the stack "object".'
unset s
echo
echo "Now compare the snapshot of the environment before we used the stack with the current state:"
echo
echo -n ' >>> '
diff -s <( printf "%s\n" "${env}" ) <( unset env RANDOM; set | grep -v '^_=' | egrep -v '(BASH_REMATCH=)')