This repository has been archived by the owner on Jun 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathindex.html
2147 lines (2133 loc) · 107 KB
/
index.html
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
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<meta content="width=device-width,initial-scale=1" name="viewport"/>
<meta content="SmokingCuke" name="author"/>
<meta content="This is the Ultimate and Final Resource on Linux shell scripting. This Site is THE Compilation of Bash Commands - It's The Only Resource You Will Need for Reference on Bash Syntax."
name="description"/>
<meta content="bash,shellscript,sh,dash,ksh,zsh,csh,shell,terminal,script,how to in bash,bash example,cheatsheet,cheat,sheet,how to,
help, stack overflow, stackoverflow, terminal, xterm, urxvt, rxvt-unicode, rxvt,arch,arch linux,cli,commandline,compare,test,operator,manjaro"
name="keywords"/>
<title>Shell Magic - The Ultimate Bash Cheatsheet!</title>
<!-- Open Graph Tags -->
<meta content="summary_large_image" name="twitter:card"/>
<meta content="@ShellMagicXyz" name="twitter:site"/>
<meta content="Shell Magic - The Ultimate Bash Reference" name="twitter:title"/>
<meta content="This is the Ultimate and Final Resource on Linux shell scripting. This Site is THE Compilation of Bash Commands - It's The Only Resource You Will Need for Reference on Bash Syntax."
name="twitter:description"/>
<meta content="https://raw.githubusercontent.com/smokingcuke/ShellMagic/master/resources/graphic/og/og-image-20-02-2020.jpg" name="twitter:image"/>
<meta content="1893" name="twitter:image:width"/>
<meta content="1080" name="twitter:image:height"/>
<meta content="1893" property="og:image:width"/>
<meta content="1080" property="og:image:height"/>
<meta content="1635546469932055" property="fb:app_id"/>
<meta content="Shell Magic" property="og:title"/>
<meta content="The Ultimate Bash Cheat Sheet!" property="og:description"/>
<meta content="website" property="og:type"/>
<meta content="en_US" property="og:locale"/>
<meta content="https://raw.githubusercontent.com/smokingcuke/ShellMagic/master/resources/graphic/og/og-image-20-02-2020.jpg" property="og:image"/>
<meta content="Screenshot displaying website content" property="og:image:alt"/>
<meta content="image/jpeg" property="og:image:type"/>
<meta content="https://shellmagic.xyz/index.html" property="og:url"/>
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-157938008-1"></script>
<!-- <script src="js/snackbar.js"></script>-->
<script src="js/modal.js"></script>
<script src="js/third-party.js"></script>
<script src="js/include-html.js"></script>
<script src="js/navigation.js"></script>
<script src="js/ajax-spa.js"></script>
<link href="node_modules/highlight.js/scss/a11y-dark.scss" rel="stylesheet">
<script src="http://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.2.0/highlight.min.js"></script>
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.2.0/styles/agate.min.css">
<script>hljs.initHighlightingOnLoad();</script>
<link href="./css/site-custom/stylesheet.css" rel="stylesheet">
<link href=“https://shellmagic.xyz/index.html”/ rel=“canonical”>
<link href="./resources/graphic/icon/favicon.ico" rel="shortcut icon" type="image/vnd.microsoft.icon">
</head>
<body onload="setNavbarLinkProperties();">
<div id="fb-root"></div>
<script async crossorigin="anonymous" defer
src="https://connect.facebook.net/en_US/sdk.js#xfbml=1&version=v6.0"></script>
<!--<div id="simpleModal_1" class="modal">-->
<!-- <div class="modal-window">-->
<!-- <div w3-include-html="./resources/code-examples/00-testing/example.sh"></div>-->
<!-- </div>-->
<!--</div>-->
<header>
<nav class="topnav">
<a href="javascript:void(0);" onclick="toggleSideNavigation()">☰</a>
<!-- <a href="javascript:void(0);" onclick="loadDoc('./content/main/flow-control.html');">About</a>-->
<!-- <a href="https://shellmagic.xyz"><i class="far fa-clone" aria-hidden="true"></i></a>-->
<a href="https://bellard.org/jslinux/vm.html?url=buildroot-x86.cfg"><i class="fas fa-terminal" aria-hidden="true"></i></a>
<!-- <a href="javascript:void(0);"><i class="fas fa-sort-down"></i></a>-->
<div class="align-right">
<a href="https://github.com/smokingcuke/ShellMagic/issues"><i class="fas fa-bug" aria-hidden="true"></i></a>
<a href="https://shellmagic.xyz"><i class="fa fa-home" aria-hidden="true"></i></a>
</div>
<div id="theme-selection">
<!--<input type="radio" name="theme" id="solarized"><label for="solarized"></label>
<input type="radio" name="theme" id="dracula"><label for="dracula"></label>
<input type="radio" name="theme" id="a-11-y-dark"><label for="a-11-y-dark"></label>
<input type="radio" name="theme" id="agate"><label for="agate"></label>
<input type="radio" name="theme" id="gml"><label for="gml"></label>
<input type="radio" name="theme" id="gruvbox-dark"><label for="gruvbox-dark"></label>
<input type="radio" name="theme" id="hopscoth"><label for="hopscoth"></label>
<input type="radio" name="theme" id="hybrid"><label for="hybrid"></label>
<input type="radio" name="theme" id="ir-black"><label for="ir-black"></label>
<input type="radio" name="theme" id="isbl-editor-dark"><label for="isbl-editor-dark"></label>
<input type="radio" name="theme" id="kimbie-dark"><label for="kimbie-dark"></label>
<input type="radio" name="theme" id="monokai-sublime"><label for="monokai-sublime"></label>
<input type="radio" name="theme" id="monokai"><label for="monokai"></label>
<input type="radio" name="theme" id="nord"><label for="nord"></label>
<input type="radio" name="theme" id="obsidian"><label for="obsidian"></label>
<input type="radio" name="theme" id="pojoaque"><label for="pojoaque"></label>
<input type="radio" name="theme" id="railscast"><label for="railscast"></label>
<input type="radio" name="theme" id="sunburst"><label for="sunburst"></label>
<input type="radio" name="theme" id="tomorrow-night-bright"><label for="tomorrow-night-bright"></label>-->
</div>
<!-- <div class="search-container">
<form action="">
<label>
<input type="text" placeholder="Quick Find" name="search">
</label>
<button type="submit"><i class="fas fa-search"></i></button>
</form>
</div>-->
</nav>
</header>
<section>
<div class="sidenav" id="sideNavigation">
<a href="#file-test-operators">File Testing</a>
<a href="#integer-comparison-operators">Integer Comparison</a>
<a href="#string-comparison-operators">String Comparison</a>
<a href="#compound-operators">Compound Operators</a>
<a href="#job-identifiers">Job Identifiers</a>
<a href="#list-constructs">List Constructs</a>
<a href="#reserved-exit-codes">Reserved Exit Codes</a>
<a href="#signals">Signals</a>
<a href="#sending-control-signals">Sending Control Signals</a>
<a href="#file-types">File Types</a>
<a href="#permissions">Permissions</a>
<a href="#string-manipulation">String Manipulation</a>
<a href="#command-parameters">Command Parameters</a>
<a href="#history-expansion">History Expansion</a>
<a href="#variable-operations">Variable Operations</a>
<a href="#bash-globbing">Bash Globbing</a>
<a href="#regular-expressions">Regular Expressions</a>
<a href="#shell-builtins">Shell Builtins</a>
<a href="#overview-of-symbols">Symbol Overview</a>
</div>
</section>
<main>
<section>
<!-- Operators for comparison could be grouped under a "conditionals" or "testing" tab -->
<div id="super-container" class="container">
<div class="row">
<div class="twelve columns" style="">
<h2 id="gradient-h1" style="">New Website Released</h2>
<p style="background: none; margin-left: auto; margin-right:auto; display: block; width: 50vw; "><a href="https://www.cheatsheet.wtf/bash">Click here to visit the improved website.</a></p>
</div>
<div class="ten columns offset-by-one">
<p class="explanation info-box shadow-box">
For a brand new version of this website, please visit: <a href="https://www.cheatsheet.wtf/bash/">www.Cheatsheet.Wtf</a>. The new website have has more cheatsheets amongst other things. This website is no longer be updated and will eventually be removed when the domain expires.
</p>
<h2 id="gradient-h1" style="margin-top: 3rem;">Bash Cheatsheet</h2>
<p class="info info-box shadow-box">
Bash (Bourne Again Shell) is a shell language build on-top of the orignal Bourne Shell which was distributed with V7 Unix in 1979 and became the standard for writing shell
scripts. Today it is primary to most Linux distributions, MacOS and it has even recently been enabled to run on Windows through something called WSL (Windows Subsystem for
Linux).
<br><br>
This reference sheet should cover most syntax, tips and other tricks there is to Bash scripting. At this moment however (because the site was only recently released) I haven't
gotten around to any explanations! But hopefully a lot of examples should be available in a few months as I'd have had the time to write explanations and script examples by
then.
</p>
</div>
</div>
<div class="row">
<div class="six columns">
<div class="shadow-box">
<h3 id="file-test-operators">File Test Operators</h3></div>
<p class="info-box info shadow-box">Testing files in scripts is easy and straight forward. This is
where
shell scripting
starts to show its glory! In Bash you can do file testing for permissions, size, date, filetype
or
existence.</p>
<!-- <p class="info-box success shadow-box text-align-center"><code class="code-no-wrap">[[ -<flag> <argument> ]]</code><br/><code class="code-no-wrap">[[ <file1> -<flag> <file2> ]]</code> </p>-->
<table class="two-column-table">
<thead>
<tr>
<th>Flag</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code data-target="simpleModal_1" data-toggle="modal">-e</code></td>
<td>File exists</td>
</tr>
<tr>
<td><code>-a</code></td>
<td>File exists (identical to -e but is deprecated and outdated)</td>
</tr>
<tr>
<td><code>-f</code></td>
<td>File is a regular file (not a directory or device file)</td>
</tr>
<tr>
<td><code>-s</code></td>
<td>file is not zero size</td>
</tr>
<tr>
<td><code>-d</code></td>
<td>file is a directory</td>
</tr>
<tr>
<td><code>-b</code></td>
<td>file is a block device</td>
</tr>
<tr>
<td><code>-c</code></td>
<td>file is a character device</td>
</tr>
<tr>
<td><code>-p</code></td>
<td>file is a pipe</td>
</tr>
<tr>
<td><code>-h</code></td>
<td>file is a symbolic link</td>
</tr>
<tr>
<td><code>-L</code></td>
<td>file is a symbolic link</td>
</tr>
<tr>
<td><code>-S</code></td>
<td>file is a socket</td>
</tr>
<tr>
<td><code>-t</code></td>
<td>file (descriptor) is associated with a terminal device; this test option may be used
to
check
whether the
stdin [ -t 0 ] or stdout [ -t 1 ] in a given script is a terminal
</td>
</tr>
<tr>
<td><code>-r</code></td>
<td>file has read permission (for the user running the test)</td>
</tr>
<tr>
<td><code>-w</code></td>
<td>file has write permission (for the user running the test)</td>
</tr>
<tr>
<td><code>-x</code></td>
<td>file has execute permission (for the user running the test)</td>
</tr>
<tr>
<td><code>-g</code></td>
<td>set-group-id (sgid) flag set on file or directory</td>
</tr>
<tr>
<td><code>-u</code></td>
<td>set-user-id (suid) flag set on file.</td>
</tr>
<tr>
<td><code>-k</code></td>
<td>sticky bit set.</td>
</tr>
<tr>
<td><code>-O</code></td>
<td>you are owner of file</td>
</tr>
<tr>
<td><code>-G</code></td>
<td>group-id of file same as yours</td>
</tr>
<tr>
<td><code>-N</code></td>
<td>file modified since it was last read</td>
</tr>
<tr>
<td><code class="code-no-wrap">f1 -nt f2</code></td>
<td>file f1 is newer than f2</td>
</tr>
<tr>
<td><code class="code-no-wrap">f1 -ot f2</code></td>
<td>file f1 is older than f2</td>
</tr>
<tr>
<td><code class="code-no-wrap">f1 -ef f2</code></td>
<td>files f1 and f2 are hard links to the same file</td>
</tr>
<tr>
<td><code>!</code></td>
<td><dfn title="A boolean operator which negates any expression.">Not</dfn> – reverses the
sense of the tests above (returns true if condition absent).
</td>
</tr>
</tbody>
</table>
<div class="shadow-box">
<h3 id="job-identifiers">Job Identifiers</h3></div>
<p class="info-box info shadow-box">Job control allows you to selectively stop (suspend) the
execution of
processes and
continue their execution at a later point in time.</p>
<table class="two-column-table">
<thead>
<tr>
<th>Notation</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>%N</code></td>
<td>Job number [N]</td>
</tr>
<tr>
<td><code>%S</code></td>
<td>Invocation (command-line) of job begins with string S</td>
</tr>
<tr>
<td><code>%?S</code></td>
<td>Invocation (command-line) of job contains within it string S</td>
</tr>
<tr>
<td><code>%%</code></td>
<td>"current" job (last job stopped in foreground or started in background)</td>
</tr>
<tr>
<td><code>%+</code></td>
<td>"current" job (last job stopped in foreground or started in background)</td>
</tr>
<tr>
<td><code>%-</code></td>
<td>Last job</td>
</tr>
<tr>
<td><code>%!</code></td>
<td>Last background process</td>
</tr>
</tbody>
</table>
<h3 class="shadow-box" id="signals">Signals</h3>
<p class="info-box info shadow-box">UNIX System V Signals.</p>
<table class="four-column-table">
<thead>
<tr>
<th>Name</th>
<th>Number</th>
<th>Action</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>SIGHUP </code></td>
<td>1</td>
<td>exit</td>
<td>Hangs up</td>
</tr>
<tr>
<td><code>SIGINT </code></td>
<td>2</td>
<td>exit</td>
<td>Interrupts.</td>
</tr>
<tr>
<td><code>SIGQUIT </code></td>
<td>3</td>
<td>core dump</td>
<td>Quits.</td>
</tr>
<tr>
<td><code>SIGILL </code></td>
<td>4</td>
<td>core dump</td>
<td>Illegal instruction.</td>
</tr>
<tr>
<td><code>SIGTRAP </code></td>
<td>5</td>
<td>core dump</td>
<td>Trace trap.</td>
</tr>
<tr>
<td><code>SIGIOT </code></td>
<td>6</td>
<td>core dump</td>
<td>IOT instruction.</td>
</tr>
<tr>
<td><code>SIGEMT </code></td>
<td>7</td>
<td>core dump</td>
<td>MT instruction.</td>
</tr>
<tr>
<td><code>SIGFPE </code></td>
<td>8</td>
<td>core dump</td>
<td>Floating point exception.</td>
</tr>
<tr>
<td><code>SIGKILL </code></td>
<td>9</td>
<td>exit</td>
<td>Kills (cannot be caught or ignored).</td>
</tr>
<tr>
<td><code>SIGBUS </code></td>
<td>10</td>
<td>core dump</td>
<td>Bus error.</td>
</tr>
<tr>
<td><code>SIGSEGV </code></td>
<td>11</td>
<td>core dump</td>
<td>Segmentation violation.</td>
</tr>
<tr>
<td><code>SIGSYS </code></td>
<td>12</td>
<td>core dump</td>
<td>Bad argument to system call.</td>
</tr>
<tr>
<td><code>SIGPIPE </code></td>
<td>13</td>
<td>exit</td>
<td>Writes on a pipe with no one to read it.</td>
</tr>
<tr>
<td><code>SIGALRM </code></td>
<td>14</td>
<td>exit</td>
<td>Alarm clock.</td>
</tr>
<tr>
<td><code>SIGTERM</code></td>
<td>15</td>
<td>exit</td>
<td>Software termination signal.</td>
</tr>
</tbody>
</table>
</div>
<div class="six columns">
<h3 class="shadow-box" id="integer-comparison-operators">Integer Comparison Operators</h3>
<p class="info-box info shadow-box">How to compare integers or arithmetic expressions in shell
scripts.</p>
<table class="two-column-table">
<thead>
<tr>
<th>Flag</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>-eq</code></td>
<td>is equal to</td>
</tr>
<tr>
<td><code>-ne</code></td>
<td>is not equal to</td>
</tr>
<tr>
<td><code>-gt</code></td>
<td>is greater than</td>
</tr>
<tr>
<td><code>-ge</code></td>
<td>is greater than or equal to</td>
</tr>
<tr>
<td><code>-lt</code></td>
<td>is less than</td>
</tr>
<tr>
<td><code>-le</code></td>
<td>is less than or equal to</td>
</tr>
<tr>
<td><code><</code></td>
<td>is less than – place within double parentheses</td>
</tr>
<tr>
<td><code><=</code></td>
<td>is less than or equal to (same rule as previous row)</td>
</tr>
<tr>
<td><code>></code></td>
<td>is greater than (same rule as previous row)</td>
</tr>
<tr>
<td><code>>=</code></td>
<td>is greater than or equal to (same rule as previous row)</td>
</tr>
</tbody>
</table>
<h3 class="shadow-box" id="string-comparison-operators">String Comparison Operators</h3>
<p class="info-box info shadow-box">String comparison in Bash.</p>
<table class="two-column-table">
<thead>
<tr>
<th>Flag</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<code>=</code>
</td>
<td>is equal to</td>
</tr>
<tr>
<td><code>==</code></td>
<td>same as above</td>
</tr>
<tr>
<td><code>!=</code></td>
<td>is not equal to</td>
</tr>
<tr>
<td><code><</code></td>
<td>is less than ASCII alphabetical order</td>
</tr>
<tr>
<td><code>></code></td>
<td>is greater than ASCII alphabetical order</td>
</tr>
<tr>
<td><code>-z</code></td>
<td>string is null (i.e. zero length)</td>
</tr>
<tr>
<td><code>-n</code></td>
<td>string is not null (i.e. !zero length)</td>
</tr>
</tbody>
</table>
<h3 class="shadow-box" id="compound-operators">Compound Operators</h3>
<p class="info-box info shadow-box">Useful for boolean expressions and is similar to <code>&&</code>
and
<code>||</code>.
The compound operators work with the <code>test</code> command or may occur within single
brackets <code>[ <expr> ].</code></p>
<table class="two-column-table">
<thead>
<tr>
<th>Flag</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>-a</code></td>
<td>logical and</td>
</tr>
<tr>
<td><code>-o</code></td>
<td>logical or</td>
</tr>
</tbody>
</table>
<div class="shadow-box">
<h3 id="list-constructs">List Constructs</h3>
</div>
<p class="info-box info shadow-box">Provides a means of processing commands consecutively and in
effect is able to replace complex if/then/case structures.</p>
<table class="two-column-table">
<thead>
<tr>
<th>Construct</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>&&</code></td>
<td>and construct</td>
</tr>
<tr>
<td><code>||</code></td>
<td>or construct</td>
</tr>
</tbody>
</table>
<div class="shadow-box">
<h3 id="reserved-exit-codes">Reserved Exit Codes</h3></div>
<p class="info-box info shadow-box">Useful for debugging a script. <dfn
title="See section about Shell Builtins.">Exit</dfn> takes integer args in the range 0-255.
</p>
<table class="two-column-table">
<thead>
<tr>
<th>Exit Code No.</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>1</code></td>
<td>Catchall for general errors</td>
</tr>
<tr>
<td><code>2</code></td>
<td>Misuse of shell builtins</td>
</tr>
<tr>
<td><code>126</code></td>
<td>Command invoked cannot execute</td>
</tr>
<tr>
<td><code>127</code></td>
<td>Command not found</td>
</tr>
<tr>
<td><code>128</code></td>
<td>Invalid argument to exit</td>
</tr>
<tr>
<td><code>128+n</code></td>
<td>Fatal error signal "n"</td>
</tr>
<tr>
<td><code>130</code></td>
<td>Script terminated by Control-C</td>
</tr>
</tbody>
</table>
<div class="shadow-box">
<h3 id="sending-control-signals">Sending Control Signals</h3></div>
<p class="info-box info shadow-box">You can use these key-combinations to send <dfn
title="A signal is a software interrupt which indicates that an important event has occurred.">signals</dfn>
</p>
<table class="two-column-table">
<thead>
<tr>
<th>Key Combo</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>Ctrl+C</code></td>
<td>The interrupt signal, sends SIGINT to the job running in the foreground.</td>
</tr>
<tr>
<td><code>Ctrl+Y</code></td>
<td>The delayed suspend character. Causes a running process to be stopped when it attempts
to read input from the terminal. Control is returned to the shell, the user can
foreground, background or kill the process. Delayed suspend is only available on
operating systems supporting this feature.
</td>
</tr>
<tr>
<td><code>Ctrl+Z</code></td>
<td>The suspend signal, sends a SIGTSTP to a running program, thus stopping it and returning
control to the shell.
</td>
</tr>
</tbody>
</table>
<p class="info-box warning shadow-box">
Check your <dfn
title="Short for set teletype. It is the command to set up a terminal. stty without options lists the current settings.">stty</dfn>
settings. Suspend and resume of output is usually disabled if you are using
"modern" terminal emulations. The standard <dfn
title="The standard terminal emulator for the X Window System, X11.">xterm</dfn> supports
Ctrl+S and Ctrl+Q by default.</p>
</div>
<div class="eight columns offset-by-two">
</div>
</div>
<div class="row">
<div class="six columns">
<div class="shadow-box">
<h3 id="file-types">File Types</h3></div>
<p class="info-box info shadow-box">This is very different from Windows but straight forward once
you
get it. I'll expand this section soon with more context.</p>
<table class="two-column-table">
<thead>
<tr>
<th>Symbol</th>
<th>Meaning</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>-</code></td>
<td>Regular file</td>
</tr>
<tr>
<td><code>d</code></td>
<td>Directory</td>
</tr>
<tr>
<td><code>l</code></td>
<td>(Symbolic) Link</td>
</tr>
<tr>
<td><code>c</code></td>
<td>Character device</td>
</tr>
<tr>
<td><code>s</code></td>
<td>Socket</td>
</tr>
<tr>
<td><code>p</code></td>
<td>Named pipe</td>
</tr>
<tr>
<td><code>b</code></td>
<td>Block device</td>
</tr>
</tbody>
</table>
<div class="shadow-box">
<h3 id="special-files">Special Files</h3></div>
<p class="info-box info shadow-box">Files that are read by the shell. Listed in order of their execution.</p>
<table class="two-column-table">
<thead>
<tr>
<th>File</th>
<th>Info</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>/etc/profile</code></td>
<td>Executed automatically at login</td>
</tr>
<tr>
<td><code>~.bash_profile</code></td>
<td rowspan="3">Whichever is found first is executed at login.</td>
</tr>
<tr>
<td><code>~/.bash_login</code></td>
</tr>
<tr>
<td><code>~.profile</code></td>
</tr>
<tr>
<td><code>~/.bashrc</code></td>
<td>Is read by every nonlogin shell.</td>
</tr>
</tbody>
</table>
</div>
<div class="six columns">
<div class="shadow-box">
<h3 id="permissions">Permissions</h3>
</div>
<p class="info-box info shadow-box">Now you may know what that arcane looking string
<code>rwxrwxrwx</code>
is when
you invoke <code class="code-no-wrap">ls -l</code></p>
<table class="two-column-table">
<thead>
<tr>
<th>Code</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>s</code></td>
<td>setuid when in <dfn
title="uuugggooo - user column (owners column) is the three first letters in this example.">user
column</dfn></td>
</tr>
<tr>
<td><code>s</code></td>
<td>setgid when in <dfn
title="uuugggooo - group column is the three middle letters in this example.">group
column</dfn></td>
</tr>
<tr>
<td><code>t</code></td>
<td>sticky bit</td>
</tr>
<tr>
<td><code>0</code></td>
<td rowspan="2">The <dfn
title="An access right may be any of the codes you see in this table">access
right</dfn>
that is supposed to be on this place is not granted.
</td>
</tr>
<tr>
<td><code>-</code></td>
</tr>
<tr>
<td><code>4</code></td>
<td rowspan="2"><dfn title="User which is affected by the category may read the file.">read
access</dfn> is granted to the user category defined in this place
</td>
</tr>
<tr>
<td><code>r</code></td>
</tr>
<tr>
<td><code>2</code></td>
<td rowspan="2"><dfn
title="User which is affected by the category may write the file. But the file is not editable in a text editor if you don't have read access.">write
permission</dfn> is granted to the user category defined in this place
</td>
</tr>
<tr>
<td><code>w</code></td>
</tr>
<tr>
<td><code>1</code></td>
<td rowspan="2">execute permission is granted to the user category defined in this place
</td>
</tr>
<tr>
<td><code>x</code></td>
</tr>
<tr>
<td><code>u</code></td>
<td>user permissions</td>
</tr>
<tr>
<td><code>g</code></td>
<td>group permissions</td>
</tr>
<tr>
<td><code>o</code></td>
<td>others permissions</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="row">
<div class="twelve columns">
<div class="shadow-box">
<h3 id="string-manipulation">String Manipulation</h3></div>
<p class="info-box info shadow-box">Bash supports a surprisingly big number of string operations!
Unfortunately, these tools lack a unified focus. Some are a subset of parameter substitution,
and others fall under the functionality of the UNIX expr command. This results in inconsistent
command syntax and overlap of functionality.</p>
<p class="info-box warning shadow-box">MacOS built-in bash is from 2007 and won't support many of
these.</p>
<table class="two-column-table code-no-wrap" style="overflow-x: scroll; max-width: 100vw;">
<thead>
<tr>
<th>Pattern</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>${#var}</code></td>
<td>Find the length of the string</td>
</tr>
<tr>
<td><code>${var%pattern}</code></td>
<td>Remove from shortest rear (end) pattern</td>
</tr>
<tr>
<td><code>${var%%pattern}</code></td>
<td>Remove from longest rear (end) pattern</td>
</tr>
<tr>
<td><code>${var:position}</code></td>
<td>Extract substring from $var at $position</td>
</tr>
<tr>
<td><code>${var:num1:num2}</code></td>
<td>Substring</td>
</tr>
<tr>
<td><code>${var#pattern}</code></td>
<td>Remove from shortest front pattern</td>
</tr>
<tr>
<td><code>${var##pattern}</code></td>
<td>Remove from longest front pattern</td>
</tr>
<tr>
<td><code>${var/pattern/string}</code></td>
<td>Find and replace (only replace first occurrence)</td>
</tr>
<tr>
<td><code>${var//pattern/string}</code></td>
<td>Find and replace all occurrences</td>
</tr>
<tr>
<td><code>${!prefix*}</code></td>
<td>Expands to the names of variables whose names begin with prefix.
</td>
</tr>
<tr>
<td><code>${var,}</code><br/><code>${var,pattern}</code></td>
<td>Convert first character to lowercase.</td>
</tr>
<tr>
<td><code>${var,,}</code><br/><code>${var,,pattern}</code></td>
<td>Convert all characters to lowercase.</td>
</tr>
<tr>
<td><code>${var^}</code><br/><code>${var^pattern}</code></td>
<td>Convert first character to uppercase.</td>
</tr>
<tr>
<td><code>${var^^}</code><br/><code>${var^^pattern}</code></td>
<td>Convert all character to uppercase.</td>
</tr>
<tr>
<td><code class="code-no-wrap">${string/substring/replacement}</code></td>
<td>Replace first match of $substring with $replacement</td>
</tr>
<tr>
<td><code class="code-no-wrap">${string//substring/replacement}</code></td>
<td>Replace all matches of $substring with $replacement</td>
</tr>
<tr>
<td><code class="code-no-wrap">${string/#substring/replacement}</code></td>
<td>If $substring matches front end of $string, substitute $replacement for $substring</td>
</tr>
<tr>
<td><code class="code-no-wrap">${string/%substring/replacement}</code></td>
<td>If $substring matches back end of $string, substitute $replacement for $substring</td>
</tr>
<tr>
<td><code class="code-no-wrap">expr match "$string" '$substring'</code></td>
<td>Length of matching $substring* at beginning of $string</td>
</tr>
<tr>
<td><code class="code-no-wrap">expr "$string" : '$substring'</code></td>
<td>Length of matching $substring* at beginning of $string</td>
</tr>
<tr>
<td><code class="code-no-wrap">expr index "$string" $substring</code></td>
<td>Numerical position in $string of first character in $substring* that matches [0 if no
match, first character counts as position 1]
</td>
</tr>
<tr>
<td><code class="code-no-wrap">expr substr $string $position $length</code></td>
<td>Extract $length characters from $string starting at $position [0 if no match, first
character counts as position 1]
</td>
</tr>
<tr>
<td><code class="code-no-wrap">expr match "$string" '\($substring\)'</code></td>
<td>Extract $substring*, searching from beginning of $string</td>
</tr>
<tr>
<td><code class="code-no-wrap">expr "$string" : '\($substring\)'</code></td>
<td>Extract $substring* , searching from beginning of $string</td>
</tr>
<tr>
<td><code class="code-no-wrap">expr match "$string" '.*\($substring\)'</code></td>
<td>Extract $substring*, searching from end of $string</td>
</tr>
<tr>
<td><code class="code-no-wrap">expr "$string" : '.*\($substring\)'</code></td>
<td>Extract $substring*, searching from end of $string</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="row">
<div class="six columns">
<div class="shadow-box">
<h3 id="quoting">Quoting</h3></div>
<p class="info-box info shadow-box">The following text shows characters or that need to be quoted if you want to use their literal symbols and not their special meaning.</p>
<table class="two-column-table">
<thead>
<tr>
<th>Symbol</th>
<th>Literal Meaning</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>;</code></td>
<td>Command seperator</td>
</tr>
<tr>
<td><code>&</code></td>
<td>Background execution</td>
</tr>
<tr>
<td><code>()</code></td>
<td>Command grouping</td>
</tr>
<tr>
<td><code>|</code></td>
<td>Pipe</td>
</tr>
<tr>
<td><code>< > &</code></td>
<td>Redirection symbols</td>
</tr>
<tr>
<td><code>* ? [ ] ~ + - @ !</code></td>
<td>Filename metacharacters</td>
</tr>
<tr>
<td><code>" ' \</code></td>
<td>Used in quoting characters</td>
</tr>
<tr>
<td><code>$</code></td>