This repository has been archived by the owner on Oct 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
bash.json
595 lines (595 loc) · 17.6 KB
/
bash.json
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
{
"id": "bash_cheat_sheet",
"name": "Bash",
"description": "Bash is a Unix shell and command language written by Brian Fox as a replacement for the Bourne shell",
"metadata": {
"sourceName": "Bash Reference Manual",
"sourceUrl": "https://www.gnu.org/software/bash/"
},
"aliases": [
"shell",
"shell language",
"posix shell",
"sh"
],
"template_type": "code",
"section_order": [
"Lingo",
"Shortcuts",
"Special Variables",
"Standard File Descriptors",
"Arithmetic Operators",
"IO Redirection",
"Expansion And Other Operators",
"Conditionals",
"Loops",
"Exit Statuses",
"Auto-Completion",
"Misc",
"TCP/UDP Sockets"
],
"sections": {
"Lingo": [
{
"key": "C",
"val": "Ctrl"
},
{
"key": "M",
"val": "Meta Key (Alt or ESC)"
}
],
"Shortcuts": [
{
"key": "C-c",
"val": "Interrupt running process"
},
{
"key": "C-z",
"val": "Suspend running process"
},
{
"key": "C-d",
"val": "Exit from current shell"
},
{
"key": "C-l",
"val": "Clear Screen"
},
{
"key": "C-a",
"val": "Move at the start of the line"
},
{
"key": "C-e",
"val": "Move at the end of the line"
},
{
"key": "M-←",
"val": "Move backward by a word"
},
{
"key": "M-b",
"val": "Move backward by a word (alternative)"
},
{
"key": "M-→",
"val": "Move forward by a word"
},
{
"key": "M-f",
"val": "Move forward by a word (alternative)"
},
{
"key": "[C-x], [C-x]",
"val": "Move cursor between start of line and current position"
},
{
"key": "M-t",
"val": "Swap the last two words before the cursor"
},
{
"key": "C-t",
"val": "Swap the last two characters before the cursor"
},
{
"key": "M-Backspace",
"val": "Delete a word (backward)"
},
{
"key": "C-w",
"val": "Delete a word (backward) (alternative)"
},
{
"key": "M-d",
"val": "Delete a word (forward)"
},
{
"key": "C-h",
"val": "Delete one character backward (same as Backspace)"
},
{
"key": "C-k",
"val": "Kill from cursor to the end of line"
},
{
"key": "C-u",
"val": "Kill from cursor to the beginning of line"
},
{
"key": "M-u",
"val": "Upper-case from cursor to the end of word"
},
{
"key": "M-l",
"val": "Lower-case from cursor to the end of word"
},
{
"key": "M-c",
"val": "Capitalize word (from cursor position)"
},
{
"key": "C-y",
"val": "Paste"
},
{
"key": "C-_",
"val": "Undo"
},
{
"key": "M-r",
"val": "Revert to original command (before editing it)"
},
{
"key": "C-p",
"val": "Get previous command"
},
{
"key": "C-n",
"val": "Get next command"
},
{
"key": "[C-r], [<pattern>]",
"val": "Search previous command containing <pattern>"
},
{
"key": "M-.",
"val": "Insert last argument of last command"
},
{
"key": "[M-<N>], [C-M-y]",
"val": "Get Nth argument of previous command (N=0 gives the command)"
},
{
"key": "M-<",
"val": "Insert oldest command from history"
},
{
"key": "[C-x], [C-v]",
"val": "Show bash version"
},
{
"key": "[C-x], [C-e]",
"val": "Edit current line with ${EDITOR}"
}
],
"Special Variables": [
{
"key": "!$",
"val": "Last argument of last command"
},
{
"key": "$<N>",
"val": "Nth argument of current process (positional parameter)"
},
{
"key": "$#",
"val": "Number of arguments given to current process"
},
{
"key": "$@",
"val": "Command line arguments for current process"
},
{
"key": "$*",
"val": "Without quotes, same as '$@'"
},
{
"key": "\"$*\"",
"val": "Command line arguments for current process, expanded to a single argument"
},
{
"key": "$0",
"val": "The name of the shell program"
},
{
"key": "$?",
"val": "Exit code of previous command"
},
{
"key": "$$",
"val": "PID of current shell or script"
},
{
"key": ":",
"val": "Dummy placeholder (produces no output)"
},
{
"key": "!-<N>",
"val": "Execute Nth command from history"
},
{
"key": "!!",
"val": "Execute last command"
},
{
"key": "!<string>",
"val": "Execute last command starting with <string>"
}
],
"Standard File Descriptors": [
{
"key": "0",
"val": "stdin"
},
{
"key": "1",
"val": "stdout"
},
{
"key": "2",
"val": "stderr"
}
],
"TCP/UDP Sockets": [
{
"key": "cat < /dev/tcp/<hostname>/<port>",
"val": "Open a TCP socket to <hostname> at <port> and write the contents of stdin"
},
{
"key": "cat < /dev/udp/<hostname>/<port>",
"val": "Open a UDP socket to <hostname> at <port> and write the contents of stdin"
}
],
"Arithmetic Operators": [
{
"key": "+",
"val": "Addition"
},
{
"key": "-",
"val": "Subtraction"
},
{
"key": "++",
"val": "Increment"
},
{
"key": "--",
"val": "Decrement"
},
{
"key": "*",
"val": "Multiplication"
},
{
"key": "/",
"val": "Division"
},
{
"key": "%",
"val": "Modulo"
},
{
"key": "**",
"val": "Exponentiation"
},
{
"key": "<<",
"val": "Bit-shift left"
},
{
"key": ">>",
"val": "Bit-shift right"
},
{
"key": "<",
"val": "Comparison (less than)"
},
{
"key": "-lt",
"val": "Comparison (less than) (alternative)"
},
{
"key": "<=",
"val": "Comparison (less than or equal)"
},
{
"key": "-le",
"val": "Comparison (less than or equal) (alternative)"
},
{
"key": ">",
"val": "Comparison (greater than)"
},
{
"key": "-gt",
"val": "Comparison (greater than) (alternative)"
},
{
"key": ">=",
"val": "Comparison (greater than or equal)"
},
{
"key": "-ge",
"val": "Comparison (greater than or equal) (alternative)"
},
{
"key": "==",
"val": "Comparison (equal)"
},
{
"key": "!=",
"val": "Comparison (not equal)"
},
{
"key": "&",
"val": "Bitwise AND"
},
{
"key": "^",
"val": "Bitwise exclusive OR"
},
{
"key": "|",
"val": "Bitwise OR"
},
{
"key": "&&",
"val": "Logical AND"
},
{
"key": "||",
"val": "Logical OR"
}
],
"IO Redirection": [
{
"key": "cmd > file",
"val": "Send cmd output to file (overwrite)"
},
{
"key": "cmd >> file",
"val": "Send cmd output to file (append)"
},
{
"key": "cmd < file",
"val": "Contents of file are passed to cmd's stdin"
},
{
"key": "cmd1 | cmd2",
"val": "Output of cmd1 is passed to cmd2's stdin"
},
{
"key": "cmd &> file",
"val": "Redirect both stdout and stderr to file (overwrite)"
},
{
"key": "cmd &>> file",
"val": "Redirect both stdout and stderr to file (append)"
},
{
"key": "cmd >&n",
"val": "Send cmd's stdout to file descriptor n"
},
{
"key": "cmd m>&n",
"val": "Same as above except that output that would normally go to file descriptor m, will also go to n"
},
{
"key": "cmd <&n",
"val": "File descriptor n becomes stdin for cmd"
},
{
"key": "cmd m<&n",
"val": "Same as above except that stdin that would normally come from file descriptor m, will now come from n"
},
{
"key": "cmd >&-",
"val": "Close stdout"
},
{
"key": "cmd <&-",
"val": "Close stdin"
}
],
"Expansion And Other Operators": [
{
"key": "${var:pos}",
"val": "Extracts substring from var at pos"
},
{
"key": "${var:pos:len}",
"val": "Extracts len characters of substring from var at pos"
},
{
"key": "${var:-val}",
"val": "If $var exists and isn't NULL, return its value; otherwise return val"
},
{
"key": "${var:=val}",
"val": "If $var exists and isn't NULL, return its value; otherwise set it to val and then return its value"
},
{
"key": "${var:?val}",
"val": "If $var exists and isn't NULL, return its value; otherwise return 'var: val' and abort"
},
{
"key": "${var:?}",
"val": "If $var exists and isn't NULL, return its value; otherwise return 'var: parameter null or not set' and abort"
},
{
"key": "${var:+val}",
"val": "If $var exists and isn't NULL, return val; otherwise return NULL"
},
{
"key": "$((...))",
"val": "Arithmetic Expansion"
},
{
"key": "${#var}",
"val": "String length operator"
},
{
"key": "${str#substr}",
"val": "Deletes shortest match of substr from front of str"
},
{
"key": "${str##substr}",
"val": "Deletes longest match of substr from front of str"
},
{
"key": "${str%substr}",
"val": "Deletes shortest match of substr from back of str"
},
{
"key": "${str%%substr}",
"val": "Deletes longest match of substr from back of str"
},
{
"key": "${str/substr/val}",
"val": "Replace first match of substr with val"
},
{
"key": "${str//substr/val}",
"val": "Replace all matches of substr with val"
},
{
"key": "${str/#substr/val}",
"val": "If $substr matches front end of str, substitute val for substr"
},
{
"key": "${str/%substr/val}",
"val": "If $substr matches back end of str, substitute val for substr"
},
{
"key": "${str^substr}",
"val": "Upper-case of first match of substr. An empty pattern selects first char."
},
{
"key": "${str^^substr}",
"val": "Upper-case of all matches of substr. An empty pattern selects the whole string."
},
{
"key": "${str,substr}",
"val": "Lower-case first match of substr. An empty pattern selects first char."
},
{
"key": "${str,,substr}",
"val": "Lower-case all matches of substr. An empty pattern selects the whole string."
}
],
"Conditionals": [
{
"key": "if \\[$hello == \"world\"\\] ; then ...; fi",
"val": "If statement"
},
{
"key": "elif \\[$hello == \"world\"\\] ; then",
"val": "Else if statement"
},
{
"key": "else",
"val": "Else statement"
},
{
"key": "fi",
"val": "End if statement"
},
{
"key": "case \"$hello\" in",
"val": "Case statement"
},
{
"key": "a) echo world ;;",
"val": "Case entry \"a\""
},
{
"key": "*) echo default ;;",
"val": "Default case entry (matches everything)"
},
{
"key": "esac",
"val": "End case statement"
}
],
"Loops": [
{
"key": "for ((i = 1; i <= 10; i++)) ; do \\[expressions\\] done",
"val": "For loop running 10 times"
},
{
"key": "for i in $list ; do \\[expressions\\] done",
"val": "For loop being executed for every item in $list"
},
{
"key": "while (i <= 10) ; do \\[expressions\\] done",
"val": "While loop"
},
{
"key": "done",
"val": "End loop"
}
],
"Exit Statuses": [
{
"key": "0",
"val": "Success"
},
{
"key": "!=0",
"val": "Failure"
}
],
"Auto-Completion": [
{
"key": "TAB",
"val": "Auto-complete (hit twice when ambiguous)"
},
{
"key": "[~], [TAB] [TAB]",
"val": "Display all users from /etc/passwd"
},
{
"key": "[$], [TAB] [TAB]",
"val": "Display all system variables"
},
{
"key": "[<string>], [M-/]",
"val": "Auto-complete/display files and directories starting with <string>"
},
{
"key": "[<string>], [M-?]",
"val": "Display commands starting with <string>"
},
{
"key": "M-*",
"val": "Insert all possible completions"
}
],
"Misc": [
{
"key": "a=$(cmd)",
"val": "$a now holds cmd's output"
},
{
"key": "a=`cmd`",
"val": "$a now holds cmd's output (alternative)"
},
{
"key": "cmd &",
"val": "Execute cmd in the background (fork)"
}
]
}
}