PageSourceSearch

https://cdn4.hola.org/www/hola/pub/dna/shell_code.js

js hola.org collected 2026-09-24 10:18:24 UTC 9,066 bytes, 399 lines download raw bytes

1;(function () {// LICENSE_CODE ZON
2  'use strict'; /*jslint browser:true, es6:true, node:true, react:true*/function _typeof(o) {"@babel/helpers - typeof";return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {return typeof o;} : function (o) {return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;}, _typeof(o);}
3  var define;
4  var is_node = (typeof module === "undefined" ? "undefined" : _typeof(module)) == 'object' && module.exports;
5  if (is_node)
6  define = require('../../../../util/require_node.js').define(module, '..');else
7
8  define = self.define;
9  define([], function () {
10    var E = {};
11    E.intro = [['div',
12    [['h1',
13    ["Shell Coding Convention"],
14    { className: "title" }],
15
16    ['p',
17    [['b',
18    ["Improvements? Suggestions?"]], " email ",
19
20
21    ['a',
22    ["[email protected]"],
23    { href: "mailto:[email protected]" }], " "]],
24
25
26
27    ['p',
28    [" Coding conventions used by other companies: ",
29    ['a',
30    ["google"],
31    { href: "https://google.github.io/styleguide/shell.xml" }], " "]]],
32
33
34
35    { className: "head" }]];
36
37    E.data = [
38    {
39      id: 'dict',
40      title: '',
41      tag: 'h2',
42      html: [],
43      "short": 'Shell'
44    },
45    {
46      id: 'general',
47      title: "General",
48      tag: 'h3',
49      "short": "General",
50      html: [['p',
51      [" In general, most of C coding convention apply to Bash coding\n                convention, for example: "]],
52
53
54      ['ul',
55      [['li',
56      ["- Indentation is always one shift-width(4):"]],
57
58      ['li',
59      ["- case has the same indentatio level and switch"]],
60
61      ['li',
62      ["- ..."]]]]]
63
64
65    },
66    {
67      id: 'function_params',
68      title: "Function parameters",
69      tag: 'h3',
70      "short": "Function parameters",
71      html: [['p',
72      ["Function parameters should define local their names, not use\n                $1, $2..."]],
73
74
75      ['div',
76      [['pre',
77      ["foo()\n{\n    cp $1 $2\n}\n"],
78
79
80
81
82      { className: "cm-s-default code bad  has-popover",
83        cat: "bad",
84        'data-content': "BAD",
85        'data-original-title': "",
86        title: "" }],
87
88      ['pre',
89      ["foo()\n{\n    local src=$1 dst=$2\n    cp $src $dst\n}\n"],
90
91
92
93
94
95      { className: "cm-s-default code good  has-popover",
96        cat: "good",
97        'data-content': "GOOD",
98        'data-original-title': "",
99        title: "" }]],
100
101      { className: "bad_good_bind" }]]
102
103    },
104    {
105      id: 'return_string',
106      title: "returning a string value:\n  RS=\"the value\"",
107
108      tag: 'h3',
109      "short": "returning a string",
110      html: [['div',
111      [['pre',
112      ["install_dir()\n{\n    echo \"/usr/local/bin\"\n}\n\ninstall app.sh `install_dir`\n"],
113
114
115
116
117
118
119      { className: "cm-s-default code bad  has-popover",
120        cat: "bad",
121        'data-content': "BAD",
122        'data-original-title': "",
123        title: "" }],
124
125      ['pre',
126      ["install_dir()\n{\n    RS=\"/usr/local/bin\"\n}\n\ninstall_dir\ninstall app.sh $RS\n"],
127
128
129
130
131
132
133
134      { className: "cm-s-default code good  has-popover",
135        cat: "good",
136        'data-content': "GOOD",
137        'data-original-title': "",
138        title: "" }]],
139
140      { className: "bad_good_bind" }]]
141
142    },
143    {
144      id: 'return_array',
145      title: "returning an array value:\n  RA=(the values...)",
146
147      tag: 'h3',
148      "short": "returning an array",
149      html: [['pre',
150      ["install_paths()\n{\n    RA=(/usr/local/bin /usr/local /etc)\n}\n\ninstall_paths\nfor p in \"${RA[@]}\"; do try_install \"$p\"; done\n"],
151
152
153
154
155
156
157
158      { className: "cm-s-default code good  has-popover",
159        cat: "good",
160        'data-content': "GOOD",
161        'data-original-title': "",
162        title: "" }]]
163
164    },
165    {
166      id: 'return_multi',
167      title: "\n  returning multiple string/array values",
168
169      tag: 'h3',
170      "short": "returning multiple string/array values",
171      html: [['p',
172      ["returning multiple string/array values use ",
173      ['code',
174      ["RS_{name}"]], " or ",
175
176
177      ['code',
178      ["RA_{name}:"]]]],
179
180
181      ['pre',
182      ["install_app()\n{\n    RS_dir=/usr/local/bin\n    RA_paths=(/usr/local/bin /usr/local /etc)\n}\n\ninstall_app\ntry_install \"$RS_dir\" \"${RA_paths[@]}\"\n"],
183
184
185
186
187
188
189
190
191      { className: "cm-s-default code good  has-popover",
192        cat: "good",
193        'data-content': "GOOD",
194        'data-original-title': "",
195        title: "" }]]
196
197    },
198    {
199      id: 'argv_handling',
200      title: "argv handling and usage()",
201      tag: 'h3',
202      "short": "argv handling",
203      html: [['p',
204      ["argv handling and usage(): use shift to process, and always\n                have usage() function:"]],
205
206
207      ['pre',
208      ["usage()\n{\n    echo \"usage: ...\"\n    exit 1\n}\nwhile [ \"${1:0:1}\" = - ]; do\n    case \"$1\" in\n    --option)\n        ... set option ...\n        ;;\n    --option-with-arg)\n        shift\n        if [ -z \"$1\" ]; then\n            usage\n        fi\n        ... use *argv to set option ...\n        ;;\n    *)\n        usage\n        ;;\n    esac\n    shift\ndone\n... handle arguments left in argv ...\nif [ -n \"$1\" ]; then\n    usage\nfi\n... start working ...\n"],
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      { className: "cm-s-default code good  has-popover",
238        cat: "good",
239        'data-content': "GOOD",
240        'data-original-title': "",
241        title: "" }]]
242
243    },
244    {
245      id: 'int_operations',
246      title: "Where\n  integer operations are relevant",
247
248      tag: 'h3',
249      "short": "Where integer operations are relevant",
250      html: [['p',
251      ["Where integer operations are relevant, use ((C_EXPRESSION))\n                instead of [SHELL_EXPRESSION]:"]],
252
253
254      ['div',
255      [['pre',
256      ["if [ \"$prep_inc\" == 1 ]; then\n    enable_prep\nfi\n"],
257
258
259
260      { className: "cm-s-default code bad  has-popover",
261        cat: "bad",
262        'data-content': "BAD",
263        'data-original-title': "",
264        title: "" }],
265
266      ['pre',
267      ["if ((prep_inc)); then\n    enable_prep\nfi\n"],
268
269
270
271      { className: "cm-s-default code good  has-popover",
272        cat: "good",
273        'data-content': "GOOD",
274        'data-original-title': "",
275        title: "" }]],
276
277      { className: "bad_good_bind" }]]
278
279    },
280    {
281      id: 'shell_expressions',
282      title: "SHELL EXPRESSIONS",
283      tag: 'h3',
284      "short": "SHELL EXPRESSIONS",
285      html: [['p',
286      ["In SHELL EXPRESSIONS use ",
287      ['code',
288      ["[[ ]]"]], " instead of ",
289
290
291      ['code',
292      ["[ ]"]], " when AND/OR is needed:"]],
293
294
295
296      ['div',
297      [['pre',
298      ["if [ -z \"$install_dir\" -o ! -d \"$install_dir\" ]; do\n    install_the_dir\nfi\n"],
299
300
301
302      { className: "cm-s-default code bad  has-popover",
303        cat: "bad",
304        'data-content': "BAD",
305        'data-original-title': "",
306        title: "" }],
307
308      ['pre',
309      ["if [[ -z \"$install_dir\" || ! -d \"$install_dir\" ]]; do\n    install_the_dir\nfi\n"],
310
311
312
313      { className: "cm-s-default code good  has-popover",
314        cat: "good",
315        'data-content': "GOOD",
316        'data-original-title': "",
317        title: "" }]],
318
319      { className: "bad_good_bind" }]]
320
321    },
322    {
323      id: 'script_included',
324      title: "When the script is included in\n  other scripts",
325
326      tag: 'h3',
327      "short": "Script included",
328      html: [['p',
329      ["When the script is included in other scripts, use the following\n                method to avoid multiple includes:"]],
330
331
332      ['pre',
333      ["  if ((__FULL_PATH_FROM_PGK_FILENAME__)); then\n      return 0\n  fi\n  __FULL_PATH_FROM_PGK_FILENAME__=1\n\nexample:\n  if ((__SYSTEM_SCRIPTS_JTOOLS_FUNCTIONS_SH__)); then\n      return 0\n  fi\n  __SYSTEM_SCRIPTS_JTOOLS_FUNCTIONS_SH__=1\n"],
334
335
336
337
338
339
340
341
342
343
344      { className: "cm-s-default code good  has-popover",
345        cat: "good",
346        'data-content': "GOOD",
347        'data-original-title': "",
348        title: "" }]]
349
350    },
351    {
352      id: 'quotation',
353      title: "Quotation:",
354      tag: 'h3',
355      html: [['p',
356      [" the sign ",
357      ['code',
358      ["$@"]], " is a special sign for all the parameters passed to the\n                function.",
359
360
361
362      ['br'], " when quoting it ",
363
364      ['code',
365      ["\"$@\""]], " bash will quote each parameter seperatly. ",
366
367
368      ['br'], " if you want to use all the parameters, you should use an\n                array:",
369
370
371      ['br'],
372      ['code',
373      ["cmd=(\"$@\")"]],
374
375      ['br'],
376      ['code',
377      ["cmd=(\"${cmd[@]}\" \"some other text\")"]],
378
379      ['br'],
380      ['code',
381      ["\"${cmd[@]}\""]],
382
383      ['br'], " The above three lines, save the parameters into an array, adds\n                to it another",
384
385
386      ['br'], " value and then us it as a bash command.",
387
388      ['br'],
389      ['br'], " Quotation should always take under consideration when passing\n                vars and arrays to other functions or when excecuted as a\n                command.",
390
391
392
393      ['br']]]]
394
395    }];
396
397    return E;
398  });})();
399//# sourceMappingURL=shell_code.js.map

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.