Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
23
Task/Arrays/UNIX-Shell/arrays-8.sh
Normal file
23
Task/Arrays/UNIX-Shell/arrays-8.sh
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
# pop ARRAY -- pop the last item on ARRAY and output it
|
||||
|
||||
pop() {
|
||||
local var=${1:?'Missing array name'}
|
||||
local x ; eval "x=\${#$var[*]}"
|
||||
if [[ $x > 0 ]]; then
|
||||
local val ; eval "val=\"\${$var[$((--x))]}\""
|
||||
unset $var[$x]
|
||||
else
|
||||
echo 1>&2 "No items in $var" ; exit 1
|
||||
fi
|
||||
echo "$val"
|
||||
}
|
||||
|
||||
alist=(a b c)
|
||||
pop alist
|
||||
a
|
||||
pop alist
|
||||
b
|
||||
pop alist
|
||||
c
|
||||
pop alist
|
||||
No items in alist
|
||||
Loading…
Add table
Add a link
Reference in a new issue