Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,6 @@
alist=( item1 item2 item3 ) # creates a 3 item array called "alist"
declare -a list2 # declare an empty list called "list2"
declare -a list3[0] # empty list called "list3"; the subscript is ignored
# create a 4 item list, with a specific order
list5=([3]=apple [2]=cherry [1]=banana [0]=strawberry)

View file

@ -0,0 +1 @@
unset alist

View file

@ -0,0 +1,2 @@
count=${#alist[*]}
echo "The number of items in alist is ${#alist[*]}"

View file

@ -0,0 +1,5 @@
x=0
while [[ $x < ${#alist[*]} ]]; do
echo "Item $x = ${alist[$x]}"
: $((x++))
done

View file

@ -0,0 +1,5 @@
x=${#alist[*]} # start with the number of items in the array
while [[ $x > 0 ]]; do # while there are items left
: $((x--)) # decrement first, because indexing is zero-based
echo "Item $x = ${alist[$x]}" # show the current item
done

View file

@ -0,0 +1 @@
alist[${#alist[*]}]=new_item

View file

@ -0,0 +1,10 @@
# shell function to append values to an array
# push LIST VALUES ...
push() {
local var=${1:?'Missing variable name!'}
shift
eval "\$$var=( \"\${$var[@]}\" \"$@\" )"
}
push alist "one thing to add"
push alist many words to add

View file

@ -0,0 +1 @@
unset alist[0]

View 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

View file

@ -0,0 +1 @@
unset alist[*]