-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharray.sh
executable file
·37 lines (29 loc) · 1.31 KB
/
array.sh
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
#!/bin/bash
# Only one-dimensional arrays are supported in bash.
#----------------------------------------------------------------------------------
# In the Bourne Again Shell, both standard and associative arrays are possible. An
# Array Variable is a variable assigned several fields of data, be they numeric, -
# alphabetic, or alphanumeric.
#
# Each field within an array is handled as though it were an individual variable, -
# but also, each field is assigned its own numeric index within an array, beginning
# with 0. Associative arrays allow for labelling each index by a string.
#
# An array could be likened to a library. The library is the array variable, but
# each index within is a book. Inside each book is data, akin to each index of an
# array variable being assigned data.
#
# - written by 'terminalforlife' (AKA: 'Learn Linux')
#----------------------------------------------------------------------------------
my_array=(A B "C" D)
#assgin value to array element
my_array[0]=E
#read array
echo "The first element: ${my_array[0]}"
echo "The second element: ${my_array[1]}"
#get all elements in array
echo "Elements in array is : ${my_array[*]}"
echo "Elements in array is : ${my_array[@]}"
#get the length of array
echo "The length of array is ${#my_array[*]}"
echo "The length of array is ${#my_array[@]}"