Debian Codegraph @

ex66.sh

raw symbols SCIP
1 #!/bin/bashscip-shell filesystem . . `/bin/bash`.
2
3
4 area[11]=23
5 area[13]=37
6 area[51]=UFOs
7
8 # Array members need not be consecutive or contiguous.
9
10 # Some members of the array can be left uninitialized.
11 # Gaps in the array are okay.
12 # In fact, arrays with sparse data ("sparse arrays")
13 #+ are useful in spreadsheet-processing software.
14
15
16 echoscip-shell system . . echo. -n "area[11] = "
17 echoscip-shell system . . echo. ${area[11]} # {curly brackets} needed.
18
19 echoscip-shell system . . echo. -n "area[13] = "
20 echoscip-shell system . . echo. ${area[13]}
21
22 echoscip-shell system . . echo. "Contents of area[51] are ${area[51]}."
23
24 # Contents of uninitialized array variable print blank (null variable).
25 echoscip-shell system . . echo. -n "area[43] = "
26 echoscip-shell system . . echo. ${area[43]}
27 echoscip-shell system . . echo. "(area[43] unassigned)"
28
29 echoscip-shell system . . echo.
30
31 # Sum of two array variables assigned to third
32 area[5]=`exprscip-shell system . . expr. ${area[11]} + ${area[13]}`
33 echoscip-shell system . . echo. "area[5] = area[11] + area[13]"
34 echoscip-shell system . . echo. -n "area[5] = "
35 echoscip-shell system . . echo. ${area[5]}
36
37 area[6]=`exprscip-shell system . . expr. ${area[11]} + ${area[51]}`
38 echoscip-shell system . . echo. "area[6] = area[11] + area[51]"
39 echoscip-shell system . . echo. -n "area[6] = "
40 echoscip-shell system . . echo. ${area[6]}
41 # This fails because adding an integer to a string is not permitted.
42
43 echoscip-shell system . . echo.; echoscip-shell system . . echo.; echoscip-shell system . . echo.
44
45 # -----------------------------------------------------------------
46 # Another array, "area2".
47 # Another way of assigning array variables...
48 # array_name=( XXX YYY ZZZ ... )
49
50 area2=( zero one two three four )
51
52 echoscip-shell system . . echo. -n "area2[0] = "
53 echoscip-shell system . . echo. ${area2[0]}
54 # Aha, zero-based indexing (first element of array is [0], not [1]).
55
56 echoscip-shell system . . echo. -n "area2[1] = "
57 echoscip-shell system . . echo. ${area2[1]} # [1] is second element of array.
58 # -----------------------------------------------------------------
59
60 echoscip-shell system . . echo.; echoscip-shell system . . echo.; echoscip-shell system . . echo.
61
62 # -----------------------------------------------
63 # Yet another array, "area3".
64 # Yet another way of assigning array variables...
65 # array_name=([xx]=XXX [yy]=YYY ...)
66
67 area3=([17]=seventeen [24]=twenty-four)
68
69 echoscip-shell system . . echo. -n "area3[17] = "
70 echoscip-shell system . . echo. ${area3[17]}
71
72 echoscip-shell system . . echo. -n "area3[24] = "
73 echoscip-shell system . . echo. ${area3[24]}
74 # -----------------------------------------------
75
76 exit 0