Skip to content

Commit 6488ab8

Browse files
committed
Fix stack.sh for bash 4.1
1 parent b043ed3 commit 6488ab8

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

prerequisites/stack.sh

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ function stack_size
9999
return 1
100100
fi
101101
# TODO: revise the eval below to eliminate the need for this pop/push
102-
# sequene, which is a workaround to prevent an error that occurs with
103-
# if the stack is new and has not been the target of a stack_push.
102+
# sequene, which is a workaround to prevent an error that occurs with
103+
# if the stack is new and has not been the target of a stack_push.
104104
stack_push $1 __push_junk
105105
stack_pop $1 __pop_trash
106106
eval "$2"='$'"{#_stack_$1[*]}"
@@ -112,7 +112,7 @@ function no_such_stack
112112
stack_exists "$1"
113113
ret=$?
114114
declare -i x
115-
let x="1-$ret"
115+
let x="1-$ret" || true
116116
return $x
117117
}
118118

@@ -183,8 +183,7 @@ function stack_print
183183

184184
while (( _i > 0 ))
185185
do
186-
(( _i = _i - 1 )) || true
187-
eval 'e=$'"{_stack_$1[$_i]}"
186+
eval 'e=$'"{_stack_$1[$((--_i))]}" # pre-decrement
188187
# shellcheck disable=SC2154
189188
tmp="$tmp $e"
190189
done
@@ -210,13 +209,8 @@ function stack_new
210209
return 1
211210
fi
212211

213-
if [[ $(uname) == "Darwin" ]]; then
214-
eval "declare -ag _stack_$1" >& /dev/null || true
215-
eval "declare -ig _stack_$1_i" >& /dev/null || true
216-
else
217-
eval "declare -ag _stack_$1" >& /dev/null
218-
eval "declare -ig _stack_$1_i" >& /dev/null
219-
fi
212+
eval "_stack_$1=()"
213+
eval "_stack_$1_i=0"
220214

221215
variableName="_stack_$1_i"
222216
variableVal="0"

0 commit comments

Comments
 (0)