-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvariable-type.drawio
More file actions
199 lines (188 loc) · 16.6 KB
/
Copy pathvariable-type.drawio
File metadata and controls
199 lines (188 loc) · 16.6 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<mxfile host="65bd71144e">
<diagram id="XEUa2ijk08846JVHwthV" name="Page-1">
<mxGraphModel dx="1422" dy="762" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="1169" pageHeight="827" math="0" shadow="0">
<root>
<mxCell id="0"/>
<mxCell id="1" parent="0"/>
<!-- ═══════════ TITLE ═══════════ -->
<mxCell id="title" value="Bash Variable Taxonomy"
style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;fontSize=20;fontStyle=1;"
vertex="1" parent="1">
<mxGeometry x="235" y="12" width="700" height="30" as="geometry"/>
</mxCell>
<mxCell id="subtitle" value="Three orthogonal dimensions: declaration type · export attribute · variable type"
style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;fontSize=11;fontStyle=2;"
vertex="1" parent="1">
<mxGeometry x="235" y="42" width="700" height="18" as="geometry"/>
</mxCell>
<!-- ═══════════ OUTER BACKGROUND ═══════════ -->
<mxCell id="bg" value=""
style="rounded=1;whiteSpace=wrap;html=1;fillColor=#f8f8f8;strokeColor=#bbbbbb;strokeWidth=2;arcSize=2;"
vertex="1" parent="1">
<mxGeometry x="28" y="66" width="1113" height="572" as="geometry"/>
</mxCell>
<!-- ═══════════ COLUMN HEADERS ═══════════ -->
<mxCell id="ch_decl" value="<b>Declared</b> <font style='font-size:10px;'>( declare / typeset / local )</font>"
style="text;html=1;strokeColor=#82b366;fillColor=#d5e8d4;align=center;verticalAlign=middle;rounded=1;fontSize=12;fontColor=#1A3D1A;"
vertex="1" parent="1">
<mxGeometry x="148" y="72" width="484" height="26" as="geometry"/>
</mxCell>
<mxCell id="ch_undecl" value="<b>Undeclared</b> <font style='font-size:10px;'>( simple assignment, no declare )</font>"
style="text;html=1;strokeColor=#82b366;fillColor=#d5e8d4;align=center;verticalAlign=middle;rounded=1;fontSize=12;fontColor=#1A3D1A;"
vertex="1" parent="1">
<mxGeometry x="640" y="72" width="484" height="26" as="geometry"/>
</mxCell>
<!-- ═══════════ ROW HEADERS ═══════════ -->
<mxCell id="rh_local" value="Shell-local<br><font style='font-size:9px'>(not exported)</font>"
style="text;html=1;strokeColor=#aaaaaa;fillColor=#f0f0f0;align=center;verticalAlign=middle;rounded=1;fontSize=11;fontStyle=1;fontColor=#333333;"
vertex="1" parent="1">
<mxGeometry x="30" y="102" width="113" height="240" as="geometry"/>
</mxCell>
<mxCell id="rh_env" value="Environment<br>Variables<br><font style='font-size:9px'>(exported)</font>"
style="text;html=1;strokeColor=#6c8ebf;fillColor=#dae8fc;align=center;verticalAlign=middle;rounded=1;fontSize=11;fontStyle=1;fontColor=#23445D;"
vertex="1" parent="1">
<mxGeometry x="30" y="374" width="113" height="240" as="geometry"/>
</mxCell>
<!-- ══════════════════════════════════════════════════ -->
<!-- CELL 1: Declared + Shell-local -->
<!-- ══════════════════════════════════════════════════ -->
<mxCell id="c1" value="Type attributes available — shell-local scope"
style="swimlane;fontStyle=2;align=center;startSize=22;fillColor=#f0f8ea;strokeColor=#82b366;rounded=1;arcSize=2;fontSize=10;fontColor=#1A3D1A;"
vertex="1" parent="1">
<mxGeometry x="148" y="102" width="484" height="240" as="geometry"/>
</mxCell>
<mxCell id="c1i1" value="<tt>declare foo=bar</tt> string scalar (default, no flag)"
style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ffffff;strokeColor=#82b366;fontSize=10;align=left;spacingLeft=8;"
vertex="1" parent="c1">
<mxGeometry x="8" y="27" width="468" height="30" as="geometry"/>
</mxCell>
<mxCell id="c1i2" value="<tt>declare -a arr=(1 2 3)</tt> indexed array"
style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ffffff;strokeColor=#82b366;fontSize=10;align=left;spacingLeft=8;"
vertex="1" parent="c1">
<mxGeometry x="8" y="63" width="468" height="30" as="geometry"/>
</mxCell>
<mxCell id="c1i3" value="<tt>declare -A map=([key]=val)</tt> associative array <font color='#888888'>(bash 4+)</font>"
style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ffffff;strokeColor=#82b366;fontSize=10;align=left;spacingLeft=8;"
vertex="1" parent="c1">
<mxGeometry x="8" y="99" width="468" height="30" as="geometry"/>
</mxCell>
<mxCell id="c1i4" value="<tt>declare -i n=42</tt> integer <font color='#555555'>(arithmetic auto-applied on assignment)</font>"
style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ffffff;strokeColor=#82b366;fontSize=10;align=left;spacingLeft=8;"
vertex="1" parent="c1">
<mxGeometry x="8" y="135" width="468" height="30" as="geometry"/>
</mxCell>
<mxCell id="c1i5" value="<tt>declare -r CONST=x</tt> read-only <font color='#555555'>(cannot be reassigned or unset)</font>"
style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ffffff;strokeColor=#82b366;fontSize=10;align=left;spacingLeft=8;"
vertex="1" parent="c1">
<mxGeometry x="8" y="171" width="468" height="30" as="geometry"/>
</mxCell>
<mxCell id="c1note" value="Flags combine: <tt>declare -air</tt> = integer + indexed array + read-only"
style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;fontSize=9;fontStyle=2;fontColor=#666666;spacingLeft=8;"
vertex="1" parent="c1">
<mxGeometry x="8" y="208" width="468" height="18" as="geometry"/>
</mxCell>
<!-- ══════════════════════════════════════════════════ -->
<!-- CELL 2: Undeclared + Shell-local -->
<!-- ══════════════════════════════════════════════════ -->
<mxCell id="c2" value="No attributes — bash infers type from usage"
style="swimlane;fontStyle=2;align=center;startSize=22;fillColor=#f0f8ea;strokeColor=#82b366;rounded=1;arcSize=2;fontSize=10;fontColor=#1A3D1A;"
vertex="1" parent="1">
<mxGeometry x="640" y="102" width="484" height="240" as="geometry"/>
</mxCell>
<mxCell id="c2i1" value="<tt>foo=bar</tt> string scalar <font color='#555555'>(always treated as a string)</font>"
style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ffffff;strokeColor=#82b366;fontSize=10;align=left;spacingLeft=8;"
vertex="1" parent="c2">
<mxGeometry x="8" y="27" width="468" height="30" as="geometry"/>
</mxCell>
<mxCell id="c2i2" value="<tt>arr=(a b c)</tt> bash auto-creates an indexed array"
style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ffffff;strokeColor=#82b366;fontSize=10;align=left;spacingLeft=8;"
vertex="1" parent="c2">
<mxGeometry x="8" y="63" width="468" height="30" as="geometry"/>
</mxCell>
<mxCell id="c2i3" value="<tt>n=42</tt> still a string <font color='#888888'>(use <tt>declare -i</tt> for integer attribute)</font>"
style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ffffff;strokeColor=#82b366;fontSize=10;align=left;spacingLeft=8;"
vertex="1" parent="c2">
<mxGeometry x="8" y="99" width="468" height="30" as="geometry"/>
</mxCell>
<mxCell id="c2note" value="No type-checking, no scope control, no read-only protection. Fine for simple scripts; use declare for reliability."
style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fffde7;strokeColor=#d6b656;fontSize=9;align=left;spacingLeft=8;verticalAlign=top;spacingTop=5;fontStyle=2;"
vertex="1" parent="c2">
<mxGeometry x="8" y="144" width="468" height="42" as="geometry"/>
</mxCell>
<!-- ═══════════ EXPORT BOUNDARY LABEL ═══════════ -->
<mxCell id="export_band" value="export / declare -x — marks the variable for inheritance by child processes"
style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;fontSize=10;fontStyle=1;fontColor=#23445D;"
vertex="1" parent="1">
<mxGeometry x="148" y="347" width="976" height="22" as="geometry"/>
</mxCell>
<!-- ══════════════════════════════════════════════════ -->
<!-- CELL 3: Declared + Exported (Environment Variable) -->
<!-- ══════════════════════════════════════════════════ -->
<mxCell id="c3" value="Declare with export attribute"
style="swimlane;fontStyle=2;align=center;startSize=22;fillColor=#e6f0fc;strokeColor=#6c8ebf;rounded=1;arcSize=2;fontSize=10;fontColor=#23445D;"
vertex="1" parent="1">
<mxGeometry x="148" y="374" width="484" height="240" as="geometry"/>
</mxCell>
<mxCell id="c3i1" value="<tt>declare -x foo=bar</tt> declare and export in one step"
style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ffffff;strokeColor=#6c8ebf;fontSize=10;align=left;spacingLeft=8;"
vertex="1" parent="c3">
<mxGeometry x="8" y="27" width="468" height="30" as="geometry"/>
</mxCell>
<mxCell id="c3i2" value="<tt>declare foo=bar; export foo</tt> declare first, add export flag after"
style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ffffff;strokeColor=#6c8ebf;fontSize=10;align=left;spacingLeft=8;"
vertex="1" parent="c3">
<mxGeometry x="8" y="63" width="468" height="30" as="geometry"/>
</mxCell>
<mxCell id="c3i3" value="<tt>declare -ix n=42</tt> exported integer <font color='#555555'>(flags compose)</font>"
style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ffffff;strokeColor=#6c8ebf;fontSize=10;align=left;spacingLeft=8;"
vertex="1" parent="c3">
<mxGeometry x="8" y="99" width="468" height="30" as="geometry"/>
</mxCell>
<mxCell id="c3warn" value="⚠ <tt>declare -ax arr</tt> — export flag is set, but <b>arrays cannot cross exec()</b>. Child processes do not receive them."
style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fff3cd;strokeColor=#d6b656;fontSize=10;align=left;spacingLeft=8;verticalAlign=top;spacingTop=5;"
vertex="1" parent="c3">
<mxGeometry x="8" y="144" width="468" height="42" as="geometry"/>
</mxCell>
<mxCell id="c3note" value="Prefer this form when you need both type attributes AND export."
style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;fontSize=9;fontStyle=2;fontColor=#666666;spacingLeft=8;"
vertex="1" parent="c3">
<mxGeometry x="8" y="194" width="468" height="18" as="geometry"/>
</mxCell>
<!-- ══════════════════════════════════════════════════ -->
<!-- CELL 4: Undeclared + Exported (Environment Variable) -->
<!-- ══════════════════════════════════════════════════ -->
<mxCell id="c4" value="Export without declare (most common pattern in shell scripts)"
style="swimlane;fontStyle=2;align=center;startSize=22;fillColor=#e6f0fc;strokeColor=#6c8ebf;rounded=1;arcSize=2;fontSize=10;fontColor=#23445D;"
vertex="1" parent="1">
<mxGeometry x="640" y="374" width="484" height="240" as="geometry"/>
</mxCell>
<mxCell id="c4i1" value="<tt>export foo=bar</tt> create and export as string scalar"
style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ffffff;strokeColor=#6c8ebf;fontSize=10;align=left;spacingLeft=8;"
vertex="1" parent="c4">
<mxGeometry x="8" y="27" width="468" height="30" as="geometry"/>
</mxCell>
<mxCell id="c4i2" value="<tt>FOO=bar; export FOO</tt> assign first, then mark for export"
style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ffffff;strokeColor=#6c8ebf;fontSize=10;align=left;spacingLeft=8;"
vertex="1" parent="c4">
<mxGeometry x="8" y="63" width="468" height="30" as="geometry"/>
</mxCell>
<mxCell id="c4i3" value="<tt>env</tt> / <tt>printenv</tt> / <tt>export -p</tt> list all environment variables"
style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ffffff;strokeColor=#6c8ebf;fontSize=10;align=left;spacingLeft=8;"
vertex="1" parent="c4">
<mxGeometry x="8" y="99" width="468" height="30" as="geometry"/>
</mxCell>
<mxCell id="c4note" value="Passed to every child process via execve(2) in the process environ[]. This is the POSIX definition of 'environment variable' — the export attribute, not the declare keyword, is what qualifies it."
style="rounded=1;whiteSpace=wrap;html=1;fillColor=#e3f2fd;strokeColor=#6c8ebf;fontSize=10;align=left;spacingLeft=8;fontStyle=2;verticalAlign=top;spacingTop=5;"
vertex="1" parent="c4">
<mxGeometry x="8" y="144" width="468" height="54" as="geometry"/>
</mxCell>
<!-- ═══════════ FOOTER DEFINITION ═══════════ -->
<mxCell id="footer" value="★ Environment Variable: any shell variable with the export attribute — it is passed to child processes via execve(2). The declare keyword is orthogonal: it adds type attributes (array, integer, readonly…) within the current shell but does not set or clear the export attribute."
style="rounded=1;whiteSpace=wrap;html=1;fillColor=#f5f5f5;strokeColor=#bbbbbb;fontSize=10;align=left;spacingLeft=12;verticalAlign=middle;fontStyle=2;"
vertex="1" parent="1">
<mxGeometry x="28" y="648" width="1113" height="48" as="geometry"/>
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>