-
Notifications
You must be signed in to change notification settings - Fork 0
/
parametersubstitution.sh
245 lines (242 loc) · 4.94 KB
/
parametersubstitution.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
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
#!/bin/bash
# ******************************************************************************************
# *
# * File: parametersubstitution.sh
# *
# * Function: demo parameters substitution rules
# *
# * Author: Franco Tommasi
# *
# * Course: Sistemi Operativi I - Facoltà di Ingegneria - Università del Salento
# *
# * Copyright: CreativeCommons 2008 - Attribution-Noncommercial-Share Alike 2.5 Generic
# *
# * Notes:
# *
# * Change History:
# * 23 febbraio 2009 23:34:56 GMT+01:00 Prima stesura
# *
# ******************************************************************************************
#
var1=abcd12345abc6789
echo var1=$var1
echo var2=$var2
echo
echo
echo '********* ${parameter:-word} **********'
echo
echo 'echo ${var1:-pasquale}' -\> ${var1:-pasquale}
echo 'echo ${var2:-pasquale}' -\> ${var2:-pasquale}
echo
echo var1=$var1
echo var2=$var2
echo
echo
echo '********* ${parameter:=word} **********'
echo
echo var1=$var1
echo var2=$var2
echo
echo 'echo ${var1:=pasquale}' -\> ${var1:=pasquale}
echo 'echo ${var2:=pasquale}' -\> ${var2:=pasquale}
echo
echo var1=$var1
echo var2=$var2
echo
echo unsetting var2 ...
unset var2
echo var2 unset
echo
echo
echo '********* ${parameter:?word} **********'
echo
echo var1=$var1
echo var2=$var2
echo
echo 'echo ${var1:?pasquale}' -\> ${var1:?pasquale}
#echo '${var2:?pasquale}' ${var2:?pasquale}
echo
echo var1=$var1
echo var2=$var2
echo
echo
echo '********* ${parameter:+word} **********'
echo
echo var1=$var1
echo var2=$var2
echo
echo 'echo ${var1:+giovanni}' -\> ${var1:+giovanni}
echo 'echo ${var2:+giovanni}' -\> ${var2:+giovanni}
echo
echo var1=$var1
echo var2=$var2
echo
echo
echo '********* ${parameter:offset} **********'
echo
echo var1=$var1
echo var2=$var2
echo
echo 'echo ${var1:0}' -\> ${var1:0}
echo 'echo ${var1:2}' -\> ${var1:2}
echo 'echo ${var1:4}' -\> ${var1:4}
echo 'echo ${var1:7}' -\> ${var1:7}
echo
echo var1=$var1
echo var2=$var2
echo
echo
echo '********* ${parameter:offset:length} **********'
echo
echo var1=$var1
echo var2=$var2
echo
echo 'echo ${var1:0:3}' -\> ${var1:0:3}
echo 'echo ${var1:2:5}' -\> ${var1:2:5}
echo 'echo ${var1:4:7}' -\> ${var1:4:7}
echo 'echo ${var1:7:1}' -\> ${var1:7:1}
echo
echo var1=$var1
echo var2=$var2
echo
echo
echo '********* ${!prefix*} **********'
echo
var2=trentatretrentini
echo assegnazione 'var2=trentatretrentini'
echo var1=$var1
echo var2=$var2
echo
echo '${!var*}' ${!var*}
echo
echo var1=$var1
echo var2=$var2
echo
echo
echo '********* ${#parameter} **********'
echo
echo var1=$var1
echo var2=$var2
echo
echo '${#var1}' ${#var1}
echo '${#var2}' ${#var2}
echo
echo var1=$var1
echo var2=$var2
echo
echo
echo '********* ${parameter#word} **********'
echo
echo var1=$var1
echo var2=$var2
echo
echo '${var1#abc}' ${var1#abc}
echo '${var2#tre}' ${var2#tre}
echo
echo var1=$var1
echo var2=$var2
echo
echo '${var1#a*c}' ${var1#a*c}
echo '${var2#t*e}' ${var2#t*e}
echo
echo var1=$var1
echo var2=$var2
echo
echo
echo '********* ${parameter##word} **********'
echo
echo var1=$var1
echo var2=$var2
echo
echo '${var1##abc}' ${var1##abc}
echo '${var2##tre}' ${var2##tre}
echo
echo var1=$var1
echo var2=$var2
echo
echo '${var1##a*c}' ${var1##a*c}
echo '${var2##t*e}' ${var2##t*e}
echo
echo var1=$var1
echo var2=$var2
echo
echo
echo '********* ${parameter%word} **********'
echo
echo var1=$var1
echo var2=$var2
echo
echo '${var1%789}' ${var1%789}
echo '${var2%ini}' ${var2%ini}
echo
echo var1=$var1
echo var2=$var2
echo
echo '${var1%a*9}' ${var1%a*9}
echo '${var2%tre*i}' ${var2%tre*i}
echo
echo var1=$var1
echo var2=$var2
echo
echo
echo '********* ${parameter%%word} **********'
echo
echo var1=$var1
echo var2=$var2
echo
echo '${var1%%789}' ${var1%%789}
echo '${var2%%ini}' ${var2%%ini}
echo
echo var1=$var1
echo var2=$var2
echo
echo '${var1%%a*9}' ${var1%%a*9}
echo '${var2%%tre*i}' ${var2%%tre*i}
echo
echo var1=$var1
echo var2=$var2
echo
echo
echo '********* ${parameter/pattern/string} **********'
echo
echo var1=$var1
echo var2=$var2
echo
echo '${var1/abc/pasquale}' ${var1/abc/pasquale}
echo '${var2/tre/quattro}' ${var2/tre/quattro}
echo
echo var1=$var1
echo var2=$var2
echo
echo '${var1/a*c/pasquale}' ${var1/a*c/pasquale}
echo '${var2/t*e/quattro}' ${var2/t*e/quattro}
echo
echo var1=$var1
echo var2=$var2
echo
echo
echo '********* ${parameter//pattern/string} **********'
echo
echo var1=$var1
echo var2=$var2
echo
echo '${var1//abc/pasquale}' ${var1//abc/pasquale}
echo '${var2//tre/quattro}' ${var2//tre/quattro}
echo
echo var1=$var1
echo var2=$var2
echo
echo '${var1//a*c/pasquale}' ${var1//a*c/pasquale}
echo '${var2//t*e/quattro}' ${var2//t*e/quattro}
echo
echo var1=$var1
echo var2=$var2
# Nei due casi precedenti: If pattern
# begins with #, it must match at the beginning of the expanded
# value of parameter. If pattern begins with %, it must match at
# the end of the expanded value of parameter. If string is null,
# matches of pattern are deleted and the / following pattern may
# be omitted.
echo
echo '********* Fine della dimostrazione **********'
echo '******* Leggere la nota nello script ********'