Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
6
Task/Arrays/UNIX-Shell/arrays-1.sh
Normal file
6
Task/Arrays/UNIX-Shell/arrays-1.sh
Normal 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)
|
||||
1
Task/Arrays/UNIX-Shell/arrays-10.sh
Normal file
1
Task/Arrays/UNIX-Shell/arrays-10.sh
Normal file
|
|
@ -0,0 +1 @@
|
|||
unset alist
|
||||
2
Task/Arrays/UNIX-Shell/arrays-2.sh
Normal file
2
Task/Arrays/UNIX-Shell/arrays-2.sh
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
count=${#alist[*]}
|
||||
echo "The number of items in alist is ${#alist[*]}"
|
||||
5
Task/Arrays/UNIX-Shell/arrays-3.sh
Normal file
5
Task/Arrays/UNIX-Shell/arrays-3.sh
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
x=0
|
||||
while [[ $x < ${#alist[*]} ]]; do
|
||||
echo "Item $x = ${alist[$x]}"
|
||||
: $((x++))
|
||||
done
|
||||
5
Task/Arrays/UNIX-Shell/arrays-4.sh
Normal file
5
Task/Arrays/UNIX-Shell/arrays-4.sh
Normal 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
|
||||
1
Task/Arrays/UNIX-Shell/arrays-5.sh
Normal file
1
Task/Arrays/UNIX-Shell/arrays-5.sh
Normal file
|
|
@ -0,0 +1 @@
|
|||
alist[${#alist[*]}]=new_item
|
||||
10
Task/Arrays/UNIX-Shell/arrays-6.sh
Normal file
10
Task/Arrays/UNIX-Shell/arrays-6.sh
Normal 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
|
||||
1
Task/Arrays/UNIX-Shell/arrays-7.sh
Normal file
1
Task/Arrays/UNIX-Shell/arrays-7.sh
Normal file
|
|
@ -0,0 +1 @@
|
|||
unset alist[0]
|
||||
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
|
||||
1
Task/Arrays/UNIX-Shell/arrays-9.sh
Normal file
1
Task/Arrays/UNIX-Shell/arrays-9.sh
Normal file
|
|
@ -0,0 +1 @@
|
|||
unset alist[*]
|
||||
Loading…
Add table
Add a link
Reference in a new issue