-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBasic_Bash_Tutorial.html
978 lines (882 loc) · 42.9 KB
/
Basic_Bash_Tutorial.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta http-equiv="X-UA-Compatible" content="IE=EDGE" />
<meta name="author" content="Author: Linton Freund ([email protected])" />
<title>Basic Bash Tutorial</title>
<script src="site_libs/header-attrs-2.20/header-attrs.js"></script>
<script src="site_libs/jquery-3.6.0/jquery-3.6.0.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="site_libs/bootstrap-3.3.5/css/cosmo.min.css" rel="stylesheet" />
<script src="site_libs/bootstrap-3.3.5/js/bootstrap.min.js"></script>
<script src="site_libs/bootstrap-3.3.5/shim/html5shiv.min.js"></script>
<script src="site_libs/bootstrap-3.3.5/shim/respond.min.js"></script>
<style>h1 {font-size: 34px;}
h1.title {font-size: 38px;}
h2 {font-size: 30px;}
h3 {font-size: 24px;}
h4 {font-size: 18px;}
h5 {font-size: 16px;}
h6 {font-size: 12px;}
code {color: inherit; background-color: rgba(0, 0, 0, 0.04);}
pre:not([class]) { background-color: white }</style>
<script src="site_libs/jqueryui-1.11.4/jquery-ui.min.js"></script>
<link href="site_libs/tocify-1.9.1/jquery.tocify.css" rel="stylesheet" />
<script src="site_libs/tocify-1.9.1/jquery.tocify.js"></script>
<script src="site_libs/navigation-1.1/tabsets.js"></script>
<script src="site_libs/navigation-1.1/codefolding.js"></script>
<link href="site_libs/font-awesome-5.1.0/css/all.css" rel="stylesheet" />
<link href="site_libs/font-awesome-5.1.0/css/v4-shims.css" rel="stylesheet" />
<style type="text/css">
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
span.underline{text-decoration: underline;}
div.column{display: inline-block; vertical-align: top; width: 50%;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
</style>
<style type="text/css">
code {
white-space: pre;
}
.sourceCode {
overflow: visible;
}
</style>
<style type="text/css" data-origin="pandoc">
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
{ counter-reset: source-line 0; }
pre.numberSource code > span
{ position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
{ content: counter(source-line);
position: relative; left: -1em; text-align: right; vertical-align: baseline;
border: none; display: inline-block;
-webkit-touch-callout: none; -webkit-user-select: none;
-khtml-user-select: none; -moz-user-select: none;
-ms-user-select: none; user-select: none;
padding: 0 4px; width: 4em;
color: #aaaaaa;
}
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; }
div.sourceCode
{ }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
code span.al { color: #ff0000; font-weight: bold; } /* Alert */
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #7d9029; } /* Attribute */
code span.bn { color: #40a070; } /* BaseN */
code span.bu { color: #008000; } /* BuiltIn */
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4070a0; } /* Char */
code span.cn { color: #880000; } /* Constant */
code span.co { color: #60a0b0; font-style: italic; } /* Comment */
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #ba2121; font-style: italic; } /* Documentation */
code span.dt { color: #902000; } /* DataType */
code span.dv { color: #40a070; } /* DecVal */
code span.er { color: #ff0000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #40a070; } /* Float */
code span.fu { color: #06287e; } /* Function */
code span.im { color: #008000; font-weight: bold; } /* Import */
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
code span.op { color: #666666; } /* Operator */
code span.ot { color: #007020; } /* Other */
code span.pp { color: #bc7a00; } /* Preprocessor */
code span.sc { color: #4070a0; } /* SpecialChar */
code span.ss { color: #bb6688; } /* SpecialString */
code span.st { color: #4070a0; } /* String */
code span.va { color: #19177c; } /* Variable */
code span.vs { color: #4070a0; } /* VerbatimString */
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
.sourceCode .row {
width: 100%;
}
.sourceCode {
overflow-x: auto;
}
.code-folding-btn {
margin-right: -30px;
}
</style>
<script>
// apply pandoc div.sourceCode style to pre.sourceCode instead
(function() {
var sheets = document.styleSheets;
for (var i = 0; i < sheets.length; i++) {
if (sheets[i].ownerNode.dataset["origin"] !== "pandoc") continue;
try { var rules = sheets[i].cssRules; } catch (e) { continue; }
var j = 0;
while (j < rules.length) {
var rule = rules[j];
// check if there is a div.sourceCode rule
if (rule.type !== rule.STYLE_RULE || rule.selectorText !== "div.sourceCode") {
j++;
continue;
}
var style = rule.style.cssText;
// check if color or background-color is set
if (rule.style.color === '' && rule.style.backgroundColor === '') {
j++;
continue;
}
// replace div.sourceCode by a pre.sourceCode rule
sheets[i].deleteRule(j);
sheets[i].insertRule('pre.sourceCode{' + style + '}', j);
}
}
})();
</script>
<style type = "text/css">
.main-container {
max-width: 940px;
margin-left: auto;
margin-right: auto;
}
img {
max-width:100%;
}
.tabbed-pane {
padding-top: 12px;
}
.html-widget {
margin-bottom: 20px;
}
button.code-folding-btn:focus {
outline: none;
}
summary {
display: list-item;
}
details > summary > p:only-child {
display: inline;
}
pre code {
padding: 0;
}
</style>
<style type="text/css">
.dropdown-submenu {
position: relative;
}
.dropdown-submenu>.dropdown-menu {
top: 0;
left: 100%;
margin-top: -6px;
margin-left: -1px;
border-radius: 0 6px 6px 6px;
}
.dropdown-submenu:hover>.dropdown-menu {
display: block;
}
.dropdown-submenu>a:after {
display: block;
content: " ";
float: right;
width: 0;
height: 0;
border-color: transparent;
border-style: solid;
border-width: 5px 0 5px 5px;
border-left-color: #cccccc;
margin-top: 5px;
margin-right: -10px;
}
.dropdown-submenu:hover>a:after {
border-left-color: #adb5bd;
}
.dropdown-submenu.pull-left {
float: none;
}
.dropdown-submenu.pull-left>.dropdown-menu {
left: -100%;
margin-left: 10px;
border-radius: 6px 0 6px 6px;
}
</style>
<script type="text/javascript">
// manage active state of menu based on current page
$(document).ready(function () {
// active menu anchor
href = window.location.pathname
href = href.substr(href.lastIndexOf('/') + 1)
if (href === "")
href = "index.html";
var menuAnchor = $('a[href="' + href + '"]');
// mark the anchor link active (and if it's in a dropdown, also mark that active)
var dropdown = menuAnchor.closest('li.dropdown');
if (window.bootstrap) { // Bootstrap 4+
menuAnchor.addClass('active');
dropdown.find('> .dropdown-toggle').addClass('active');
} else { // Bootstrap 3
menuAnchor.parent().addClass('active');
dropdown.addClass('active');
}
// Navbar adjustments
var navHeight = $(".navbar").first().height() + 15;
var style = document.createElement('style');
var pt = "padding-top: " + navHeight + "px; ";
var mt = "margin-top: -" + navHeight + "px; ";
var css = "";
// offset scroll position for anchor links (for fixed navbar)
for (var i = 1; i <= 6; i++) {
css += ".section h" + i + "{ " + pt + mt + "}\n";
}
style.innerHTML = "body {" + pt + "padding-bottom: 40px; }\n" + css;
document.head.appendChild(style);
});
</script>
<!-- tabsets -->
<style type="text/css">
.tabset-dropdown > .nav-tabs {
display: inline-table;
max-height: 500px;
min-height: 44px;
overflow-y: auto;
border: 1px solid #ddd;
border-radius: 4px;
}
.tabset-dropdown > .nav-tabs > li.active:before, .tabset-dropdown > .nav-tabs.nav-tabs-open:before {
content: "\e259";
font-family: 'Glyphicons Halflings';
display: inline-block;
padding: 10px;
border-right: 1px solid #ddd;
}
.tabset-dropdown > .nav-tabs.nav-tabs-open > li.active:before {
content: "\e258";
font-family: 'Glyphicons Halflings';
border: none;
}
.tabset-dropdown > .nav-tabs > li.active {
display: block;
}
.tabset-dropdown > .nav-tabs > li > a,
.tabset-dropdown > .nav-tabs > li > a:focus,
.tabset-dropdown > .nav-tabs > li > a:hover {
border: none;
display: inline-block;
border-radius: 4px;
background-color: transparent;
}
.tabset-dropdown > .nav-tabs.nav-tabs-open > li {
display: block;
float: none;
}
.tabset-dropdown > .nav-tabs > li {
display: none;
}
</style>
<!-- code folding -->
<style type="text/css">
.code-folding-btn { margin-bottom: 4px; }
</style>
<style type="text/css">
#TOC {
margin: 25px 0px 20px 0px;
}
@media (max-width: 768px) {
#TOC {
position: relative;
width: 100%;
}
}
@media print {
.toc-content {
/* see https://github.com/w3c/csswg-drafts/issues/4434 */
float: right;
}
}
.toc-content {
padding-left: 30px;
padding-right: 40px;
}
div.main-container {
max-width: 1200px;
}
div.tocify {
width: 20%;
max-width: 260px;
max-height: 85%;
}
@media (min-width: 768px) and (max-width: 991px) {
div.tocify {
width: 25%;
}
}
@media (max-width: 767px) {
div.tocify {
width: 100%;
max-width: none;
}
}
.tocify ul, .tocify li {
line-height: 20px;
}
.tocify-subheader .tocify-item {
font-size: 0.90em;
}
.tocify .list-group-item {
border-radius: 0px;
}
</style>
</head>
<body>
<div class="container-fluid main-container">
<!-- setup 3col/9col grid for toc_float and main content -->
<div class="row">
<div class="col-xs-12 col-sm-4 col-md-3">
<div id="TOC" class="tocify">
</div>
</div>
<div class="toc-content col-xs-12 col-sm-8 col-md-9">
<div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-bs-toggle="collapse" data-target="#navbar" data-bs-target="#navbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.html">The Resources</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>
<a href="index.html">Home</a>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Workflows
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="amplicon_workflow.html">
<span class="fa fa-solid fa-dna"></span>
Amplicon Sequencing Worfklow
</a>
</li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Tutorials
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="Basic_Bash_Tutorial.html">
<span class="fa fa-solid fa-terminal"></span>
Bash Basics Tutorial
</a>
</li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
</ul>
</div><!--/.nav-collapse -->
</div><!--/.container -->
</div><!--/.navbar -->
<div id="header">
<div class="btn-group pull-right float-right">
<button type="button" class="btn btn-default btn-xs btn-secondary btn-sm dropdown-toggle" data-toggle="dropdown" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><span>Code</span> <span class="caret"></span></button>
<ul class="dropdown-menu dropdown-menu-right" style="min-width: 50px;">
<li><a id="rmd-show-all-code" href="#">Show All Code</a></li>
<li><a id="rmd-hide-all-code" href="#">Hide All Code</a></li>
</ul>
</div>
<h1 class="title toc-ignore">Basic Bash Tutorial</h1>
<h4 class="author">Author: Linton Freund (<a
href="mailto:[email protected]" class="email">[email protected]</a>)</h4>
<h4 class="date">Last update: 02 October, 2023</h4>
</div>
<style type="text/css">
body{
font-size: 13pt;
}
</style>
<!--
Render from R:
rmarkdown::render("Basic_Bash_Tutorial.Rmd", clean=TRUE, output_format="html_document")
R
Rendering from the command-line. To render to PDF format, use the argument setting: output_format="pdf_document".
$ Rscript -e "rmarkdown::render('Basic_Bash_Tutorial.Rmd', output_format='html_document', clean=TRUE)"
-->
<div id="welcome" class="section level1" number="1">
<h1><span class="header-section-number">1</span> Welcome</h1>
<p>This tutorial is a collection of helpful Bash commands as well as
some different loops that you can use for your own scripts. These tricks
are things I have picked up along the way, and admittedly, things I
often forget if I am not using them. If you are overwhelmed by this, or
forget certain things, do not stress! Google is your best friend when it
comes to coding, and you can always find help that way.</p>
<p>This tutorial uses two text files (XCZO_MapFile_copy.txt,
codon_table_copy.txt) that you need to follow along. You can download
these files <a
href="https://github.com/hlfreund/workflows.github.io/tree/main/Basic_Bash_Tutorial_Files">here</a>.
However, you can use these commands with any and all files at your
disposal - just be sure not to delete any of your files without triple
checking, or making a copy!</p>
<div id="what-is-bash" class="section level2" number="1.1">
<h2><span class="header-section-number">1.1</span> What is Bash?</h2>
<p>Simply, bash is a coding language that we can use to interact with
our operating system, particularly a Unix-based operating system (OS).
Unix and Linux operating systems are similar, so you can use bash to
interact with these types of OS.</p>
<p>We use bash in the <strong>shell</strong> or <strong>command-line
interpreter</strong> to tell the computer what we need it to do. On a
Mac, we usually use the Terminal ap as our shell, whereas on Windows you
can use the command prompt app as your shell.</p>
<p>For more information on Bash, check out its Wiki page <a
href="https://en.wikipedia.org/wiki/Bash_(Unix_shell)">here</a> and look
into this helpful bash/linux tutorial <a
href="https://linuxconfig.org/bash-scripting-tutorial-for-beginners">here</a>.</p>
</div>
</div>
<div id="a-crash-course-in-bash" class="section level1" number="2">
<h1><span class="header-section-number">2</span> A Crash Course in
Bash</h1>
<p>Let’s start with some simple basics and work our way up! Just to
reiterate, these are JUST the basics. Please use this tutorial as a
jumping off point for learning more about bash.</p>
<div id="the-basics" class="section level2" number="2.1">
<h2><span class="header-section-number">2.1</span> The Basics</h2>
<p><code>pwd</code> will print the directory we are currently in.
<code>ls</code> prints everything that is in our current directory. Find
more options for <code>ls</code> <a
href="https://linux.die.net/man/1/ls">here</a>.</p>
<div class="sourceCode" id="cb1"><pre
class="sourceCode bash"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" tabindex="-1"></a><span class="bu">pwd</span> <span class="co"># print current working directory, aka where you are in your computer</span></span></code></pre></div>
<center>
<img src="Basic_Bash_Tutorial_Files/pwd_example.png" />
</center>
<div align="center">
Figure 1a: Example of <code>pwd</code> output
</div>
<p></br></p>
<div class="sourceCode" id="cb2"><pre
class="sourceCode bash"><code class="sourceCode bash"><span id="cb2-1"><a href="#cb2-1" tabindex="-1"></a><span class="fu">ls</span> <span class="at">-l</span> <span class="co"># list items in your current directory in a long list format</span></span>
<span id="cb2-2"><a href="#cb2-2" tabindex="-1"></a><span class="fu">ls</span> <span class="at">-ltr</span> <span class="co"># list items in your current directory in long list format, reverse sort by time</span></span></code></pre></div>
<center>
<img src="Basic_Bash_Tutorial_Files/ls_l_example.png" />
</center>
<div align="center">
Figure 1b: Example of <code>ls -l</code> output
</div>
<p></br></p>
<center>
<img src="Basic_Bash_Tutorial_Files/ls_ltr_example.png" />
</center>
<div align="center">
Figure 1b: Example of <code>ls -ltr</code> output
</div>
<p></br></p>
<p>Let’s make a directory called <code>test_dir</code> and get into that
directory. From there, we can create a text file called
<code>test.txt</code> and read this text file in the terminal.</p>
<div class="sourceCode" id="cb3"><pre
class="sourceCode bash"><code class="sourceCode bash"><span id="cb3-1"><a href="#cb3-1" tabindex="-1"></a><span class="fu">mkdir</span> test_dir <span class="co"># mkdir creates a directory</span></span>
<span id="cb3-2"><a href="#cb3-2" tabindex="-1"></a><span class="bu">cd</span> test_dir <span class="co"># cd stands for change directory</span></span>
<span id="cb3-3"><a href="#cb3-3" tabindex="-1"></a></span>
<span id="cb3-4"><a href="#cb3-4" tabindex="-1"></a><span class="fu">touch</span> test.txt <span class="co"># touch is a command used for creating a file (not editing)</span></span>
<span id="cb3-5"><a href="#cb3-5" tabindex="-1"></a><span class="fu">nano</span> test.txt <span class="co"># nano is a command used to create OR edit a file, in this case we are editing test.txt</span></span>
<span id="cb3-6"><a href="#cb3-6" tabindex="-1"></a><span class="fu">cat</span> test.txt <span class="co"># cat is how to read a file</span></span>
<span id="cb3-7"><a href="#cb3-7" tabindex="-1"></a><span class="fu">rm</span> test.txt <span class="co"># how to delete a file(s) from your directory</span></span></code></pre></div>
<center>
<img src="Basic_Bash_Tutorial_Files/nano_example.png" />
</center>
<div align="center">
Figure 2: <code>nano</code> File edit screen for file called “test.txt”
</div>
<p></br></p>
<p>To go back to your previous directory in your <strong>path</strong>
(aka folder/you/are/in), do the following</p>
<div class="sourceCode" id="cb4"><pre
class="sourceCode bash"><code class="sourceCode bash"><span id="cb4-1"><a href="#cb4-1" tabindex="-1"></a><span class="bu">cd</span> .. <span class="co"># change directory to previous directory in path</span></span>
<span id="cb4-2"><a href="#cb4-2" tabindex="-1"></a><span class="bu">pwd</span></span></code></pre></div>
<p>Now let’s try some other commands we can use to seeing what is in a
file. <code>head</code> can show us the first 10 lines of a file, and
<code>tail</code> can show us the last 10 lines of a file.</p>
<div class="sourceCode" id="cb5"><pre
class="sourceCode bash"><code class="sourceCode bash"><span id="cb5-1"><a href="#cb5-1" tabindex="-1"></a><span class="fu">head</span> XCZO_MapFile_copy.txt <span class="co"># read first 10 lines of file</span></span>
<span id="cb5-2"><a href="#cb5-2" tabindex="-1"></a><span class="fu">head</span> n <span class="at">-15</span> XCZO_MapFile_copy.txt <span class="co"># read first 15 lines of file</span></span>
<span id="cb5-3"><a href="#cb5-3" tabindex="-1"></a><span class="fu">tail</span> XCZO_MapFile_copy.txt <span class="co"># read last 10 lines of file; uses -n in same way that head does</span></span></code></pre></div>
<center>
<img src="Basic_Bash_Tutorial_Files/head_xczo_file_example.png" />
</center>
<div align="center">
Figure 3: Head of “XCZO_MapFile_copy.txt”. Full file could not be fit
into image.
</div>
<p></br></p>
<p>We can also use the <code>more</code> function to read files page by
page, using the <em>spacebar</em> to go to each page. Or, we can use the
<code>less</code> function to read the files line by line, using the
up/down arrows to navigate. These functions are very similar, however,
less is a bit faster because it does not load the entire file as you
read it.</p>
<div class="sourceCode" id="cb6"><pre
class="sourceCode bash"><code class="sourceCode bash"><span id="cb6-1"><a href="#cb6-1" tabindex="-1"></a><span class="fu">more</span> XCZO_MapFile_copy.txt <span class="co"># read file by page. Use "space" to go to next page.</span></span>
<span id="cb6-2"><a href="#cb6-2" tabindex="-1"></a><span class="co"># to quit, just type "q" and enter</span></span>
<span id="cb6-3"><a href="#cb6-3" tabindex="-1"></a></span>
<span id="cb6-4"><a href="#cb6-4" tabindex="-1"></a><span class="fu">less</span> XCZO_MapFile_copy.txt <span class="co"># read file by line. Use arrows to navigate up or down the page. Has more options than more</span></span>
<span id="cb6-5"><a href="#cb6-5" tabindex="-1"></a><span class="co"># to quit, just type "q" and enter</span></span></code></pre></div>
<p>We can also move the file around or rename the file with the
<code>mv</code> command, and make a copy of this file using the
<code>cp</code> command.</p>
<div class="sourceCode" id="cb7"><pre
class="sourceCode bash"><code class="sourceCode bash"><span id="cb7-1"><a href="#cb7-1" tabindex="-1"></a><span class="fu">mkdir</span> newdir <span class="co"># we will move our file into this directory</span></span>
<span id="cb7-2"><a href="#cb7-2" tabindex="-1"></a><span class="fu">mv</span> XCZO_MapFile_copy.txt newdir <span class="co"># move file into newdir</span></span>
<span id="cb7-3"><a href="#cb7-3" tabindex="-1"></a></span>
<span id="cb7-4"><a href="#cb7-4" tabindex="-1"></a><span class="bu">cd</span> newdir</span>
<span id="cb7-5"><a href="#cb7-5" tabindex="-1"></a><span class="fu">ls</span> <span class="at">-ltr</span> <span class="co"># what is in our directory?</span></span>
<span id="cb7-6"><a href="#cb7-6" tabindex="-1"></a></span>
<span id="cb7-7"><a href="#cb7-7" tabindex="-1"></a><span class="fu">mv</span> XCZO_MapFile_copy.txt XCZO_Map.txt <span class="co"># rename file XCZO_MapFile_copy.txt to XCZO_Map.txt with mv</span></span>
<span id="cb7-8"><a href="#cb7-8" tabindex="-1"></a><span class="fu">ls</span> <span class="at">-ltr</span> <span class="co"># sanity check - always good practice to see if your previous step worked!</span></span>
<span id="cb7-9"><a href="#cb7-9" tabindex="-1"></a><span class="bu">cd</span> ..</span>
<span id="cb7-10"><a href="#cb7-10" tabindex="-1"></a></span>
<span id="cb7-11"><a href="#cb7-11" tabindex="-1"></a><span class="fu">cp</span> newdir/XCZO_Map.txt . <span class="co"># copy file in newdir to current working directory, represented by "."</span></span>
<span id="cb7-12"><a href="#cb7-12" tabindex="-1"></a><span class="fu">cp</span> newdir/<span class="pp">*</span> . <span class="co"># copy ALL files in newdir to current directory; "*" represents every file in newdir</span></span>
<span id="cb7-13"><a href="#cb7-13" tabindex="-1"></a></span>
<span id="cb7-14"><a href="#cb7-14" tabindex="-1"></a><span class="co"># sanity check - did our copy just work?</span></span>
<span id="cb7-15"><a href="#cb7-15" tabindex="-1"></a><span class="bu">cd</span> newdir</span>
<span id="cb7-16"><a href="#cb7-16" tabindex="-1"></a><span class="fu">ls</span> <span class="at">-ltr</span></span>
<span id="cb7-17"><a href="#cb7-17" tabindex="-1"></a><span class="bu">cd</span> ..</span></code></pre></div>
</div>
<div id="loops" class="section level2" number="2.2">
<h2><span class="header-section-number">2.2</span> Loops</h2>
<p>These commands are great, but what if you need to do the same action
on hundreds of files!? For example, what if you are reading a file of
amplicon sequences and want to cound the number of sequences in each
file, and save that information? That is when we can use the magic of
loops in our scripts! Loops are not specific to bash, but you will find
that a lot of languages (like R & Python) model their loop
structures after the loops in bash.</p>
<p>All the helpful flowcharts included below for each loop type come
from <a
href="https://www.zenflowchart.com/blog/for-loop-flowchart">ZenFlowchart</a>.</p>
<div id="while-read-loops" class="section level3" number="2.2.1">
<h3><span class="header-section-number">2.2.1</span> While Read
Loops</h3>
<p>If we want to read every line in the file, we can create a
<code>while loop</code> to run through each line of the file, and use
the <code>echo</code> command to print out the contents of each
line.</p>
<p>The logic of the while loop is the following: while read x (line,
string, etc), do x.</p>
<center>
<img src="Basic_Bash_Tutorial_Files/while-loop-example.png" />
</center>
<div align="center">
Figure 4a: While Loop Flowchart. <a
href="https://www.zenflowchart.com/blog/for-loop-flowchart">source</a>
</div>
<p></br></p>
<div class="sourceCode" id="cb8"><pre
class="sourceCode bash"><code class="sourceCode bash"><span id="cb8-1"><a href="#cb8-1" tabindex="-1"></a><span class="cf">while</span> <span class="bu">read</span> <span class="va">line</span></span>
<span id="cb8-2"><a href="#cb8-2" tabindex="-1"></a><span class="cf">do</span></span>
<span id="cb8-3"><a href="#cb8-3" tabindex="-1"></a> <span class="bu">echo</span> <span class="va">$line</span> <span class="co"># prints every line, defined by $line variable</span></span>
<span id="cb8-4"><a href="#cb8-4" tabindex="-1"></a><span class="cf">done</span> <span class="op"><</span> codon_table_copy.txt <span class="co"># this is how we feed the input file into the while read loop</span></span></code></pre></div>
</div>
<div id="for-loops" class="section level3" number="2.2.2">
<h3><span class="header-section-number">2.2.2</span> For Loops</h3>
<p>If we want to be just a tad fancy, we can use a <code>for loop</code>
and the <code>echo</code> command to print everything in our directory.
We can loop through every file in our current directory by using the
<code>*</code> as a wildcard. This <code>*</code> is an example of what
we call a <strong>regular expression</strong> (aka regex) - basically,
the <code>*</code> can be used to as a wildcard character to represent
everything, OR it can be used as the asterisk itself.</p>
<p>Another example of a regex is the <code>.</code>, which can indicate
both our current working directory, characters we are editing, or as a
period itself.</p>
<p>To review, the logic of the for loop is the following: for x (a file,
a line, anything you want) in this, do the following. This will loop
repeteadly until all of the actions in the for statement are done.</p>
<center>
<img src="Basic_Bash_Tutorial_Files/for-loop-flowchart-example.png" />
</center>
<div align="center">
Figure 4b: For Loop Flowchart. <a
href="https://www.zenflowchart.com/blog/for-loop-flowchart">source</a>
</div>
<p></br></p>
<div class="sourceCode" id="cb9"><pre
class="sourceCode bash"><code class="sourceCode bash"><span id="cb9-1"><a href="#cb9-1" tabindex="-1"></a><span class="cf">for</span> FILE <span class="kw">in</span> <span class="pp">*</span><span class="kw">;</span> <span class="co"># for every FILE in our directory; "*" is a wildcard used to represent every thing</span></span>
<span id="cb9-2"><a href="#cb9-2" tabindex="-1"></a><span class="cf">do</span></span>
<span id="cb9-3"><a href="#cb9-3" tabindex="-1"></a> <span class="bu">echo</span> <span class="va">$FILE</span> <span class="co"># prints $FILE variable; use $ to call a variable later in loop or code</span></span>
<span id="cb9-4"><a href="#cb9-4" tabindex="-1"></a><span class="cf">done</span></span>
<span id="cb9-5"><a href="#cb9-5" tabindex="-1"></a></span>
<span id="cb9-6"><a href="#cb9-6" tabindex="-1"></a><span class="co"># Here, FILE is a variable you are creating and assigning to every file in your current directory</span></span>
<span id="cb9-7"><a href="#cb9-7" tabindex="-1"></a><span class="co">## You can refer to this variable later using the $</span></span></code></pre></div>
</div>
<div id="if-else-loops" class="section level3" number="2.2.3">
<h3><span class="header-section-number">2.2.3</span> If-Else Loops</h3>
<p>If we want to get a little fancier, we can use an
<code>if else</code> loop to create directories. Personally, I really
like using this trick when I want to make a directory, but I don’t know
if it already exists. The <code>!</code> is the same as “not” - so for
the code below, I am checking if the directory (specificed with -d
argument) does NOT exist.</p>
<p>In summary, the if loop logic here is: if this directory does NOT
exist, then make directory. Otherwise, the directory exists, and nothing
is done by the loop.</p>
<center>
<img src="Basic_Bash_Tutorial_Files/if-else-loop-example.png" />
</center>
<div align="center">
Figure 4c: If-Else Loop Flowchart. <a
href="https://www.zenflowchart.com/blog/for-loop-flowchart">source</a>
</div>
<p></br></p>
<div class="sourceCode" id="cb10"><pre
class="sourceCode bash"><code class="sourceCode bash"><span id="cb10-1"><a href="#cb10-1" tabindex="-1"></a><span class="cf">if</span> <span class="kw">[[</span> <span class="ot">!</span> <span class="ot">-d</span> ./testdir <span class="kw">]];</span> <span class="cf">then</span></span>
<span id="cb10-2"><a href="#cb10-2" tabindex="-1"></a> <span class="co"># [[ ! -d {dir} ]] --> checks if the directory dir does NOT exist</span></span>
<span id="cb10-3"><a href="#cb10-3" tabindex="-1"></a> <span class="fu">mkdir</span> testdir</span>
<span id="cb10-4"><a href="#cb10-4" tabindex="-1"></a><span class="cf">fi</span></span>
<span id="cb10-5"><a href="#cb10-5" tabindex="-1"></a></span>
<span id="cb10-6"><a href="#cb10-6" tabindex="-1"></a><span class="fu">rm</span> <span class="at">-r</span> testdir <span class="co"># how to delete a directory - recursive removal</span></span></code></pre></div>
</div>
</div>
<div id="word-count-grep" class="section level2" number="2.3">
<h2><span class="header-section-number">2.3</span> Word Count &
Grep</h2>
<p>In scenarios when we have really long files, or are looking for
specific information within or about the file, there are several
commands we can use. <code>grep</code> is an extremely powerful way to
find certain patterns in your files/directories. There is a
<code>find</code> command in bash, but we will not go over that
here.</p>
<p>We can also use tools like <code>wc</code> to figure out how many
words (or lines or other pieces of information) are in our file of
interest.</p>
<div class="sourceCode" id="cb11"><pre
class="sourceCode bash"><code class="sourceCode bash"><span id="cb11-1"><a href="#cb11-1" tabindex="-1"></a><span class="fu">wc</span> codon_table_copy.txt <span class="co"># wc is the "word count" command</span></span>
<span id="cb11-2"><a href="#cb11-2" tabindex="-1"></a><span class="co">## for wc - first column shows line count, second column shows word count, third column shows character count</span></span>
<span id="cb11-3"><a href="#cb11-3" tabindex="-1"></a></span>
<span id="cb11-4"><a href="#cb11-4" tabindex="-1"></a><span class="fu">wc</span> <span class="at">-l</span> codon_table_copy.txt <span class="co"># count number of lines in file</span></span>
<span id="cb11-5"><a href="#cb11-5" tabindex="-1"></a></span>
<span id="cb11-6"><a href="#cb11-6" tabindex="-1"></a><span class="fu">grep</span> Stop codon_table_copy.txt <span class="co"># find the Stop codons in the file</span></span>
<span id="cb11-7"><a href="#cb11-7" tabindex="-1"></a><span class="fu">grep</span> Stop codon_table_copy.txt <span class="kw">|</span> <span class="fu">wc</span> <span class="at">-l</span> <span class="co"># find Stop codons, then count number of them by counting the lines</span></span>
<span id="cb11-8"><a href="#cb11-8" tabindex="-1"></a></span>
<span id="cb11-9"><a href="#cb11-9" tabindex="-1"></a><span class="co">## | is a pipe that is used to string multiple commands together</span></span></code></pre></div>
<center>
<img src="Basic_Bash_Tutorial_Files/wc_grep_examples.png" />
</center>
<div align="center">
Figure 5a: Examples of <code>wc</code> and <code>grep</code> outputs.
</div>
<p></br></p>
<p>We can also <code>sort</code> these files and pull out pieces of
unique (<code>uniq</code>) information from said files, like unique gene
IDs or protein names, etc. We can also be very specific as to where we
search/sort by using the <code>cut</code> command to specify which
sections/pieces we are cutting from.</p>
<div class="sourceCode" id="cb12"><pre
class="sourceCode bash"><code class="sourceCode bash"><span id="cb12-1"><a href="#cb12-1" tabindex="-1"></a><span class="fu">grep</span> Stop codon_table_copy.txt <span class="kw">|</span> <span class="fu">sort</span> <span class="co"># sorts the order in which these lines with the word "Stop" are arranged in the output; automatically sorts alphabetically in descending order</span></span>
<span id="cb12-2"><a href="#cb12-2" tabindex="-1"></a></span>
<span id="cb12-3"><a href="#cb12-3" tabindex="-1"></a><span class="fu">grep</span> Arginine codon_table_copy.txt <span class="kw">|</span> <span class="fu">sort</span> <span class="kw">|</span> <span class="fu">cut</span> <span class="at">-f</span> 3 <span class="co"># cut by field; in this case 3rd field is kept and rest are removed</span></span>
<span id="cb12-4"><a href="#cb12-4" tabindex="-1"></a><span class="co"># fields are designated by whatever delimiter is used. For example, in a .csv file, the delimiter is ",", so each field is separated by a ","</span></span>
<span id="cb12-5"><a href="#cb12-5" tabindex="-1"></a><span class="co">## ^ searches for Arginine, sorts output of grep, and cuts third field (a column in this case) and returns output only from 3rd field</span></span>
<span id="cb12-6"><a href="#cb12-6" tabindex="-1"></a></span>
<span id="cb12-7"><a href="#cb12-7" tabindex="-1"></a><span class="fu">grep</span> Arginine codon_table_copy.txt <span class="kw">|</span> <span class="fu">sort</span> <span class="kw">|</span> <span class="fu">cut</span> <span class="at">-f</span> 3 <span class="kw">|</span> <span class="fu">uniq</span> <span class="co"># uniq returns only unique or individual instances of text in file(s) - great for checking out duplicates and the number of duplicates</span></span>
<span id="cb12-8"><a href="#cb12-8" tabindex="-1"></a></span>
<span id="cb12-9"><a href="#cb12-9" tabindex="-1"></a><span class="fu">cut</span> <span class="at">-f3</span> codon_table_copy.txt <span class="kw">|</span> <span class="fu">sort</span> <span class="kw">|</span> <span class="fu">uniq</span> <span class="at">-c</span> <span class="co"># cuts third field based on tab (\t); sorts 3rd field, then finds unique instances of each string and counts them</span></span>
<span id="cb12-10"><a href="#cb12-10" tabindex="-1"></a></span>
<span id="cb12-11"><a href="#cb12-11" tabindex="-1"></a><span class="co"># cut can also cut fields based on any delimiter - the default delimiter is tab (\t)</span></span></code></pre></div>
<center>
<img src="Basic_Bash_Tutorial_Files/grep_sort_cut_examples.png" />
</center>
<div align="center">
Figure 5b: Examples of <code>grep</code>,<code>sort</code>,
<code>cut</code>, and <code>uniq</code> outputs.
</div>
<p></br></p>
</div>
<div id="transform-and-streamline-editor-aka-sed" class="section level2"
number="2.4">
<h2><span class="header-section-number">2.4</span> Transform and
Streamline Editor (aka sed)</h2>
<p>Finally, we can edit files using the transform command
<code>tr</code> or the streamline editor command <code>sed</code>.</p>
<p>Transform or <code>tr</code> is used to make small edits across the
entire file. For example, if you wanted to delete all of the spaces from
a file, or if you wanted to switch all of your spaces to a tab, then you
can use transform.</p>
<div class="sourceCode" id="cb13"><pre
class="sourceCode bash"><code class="sourceCode bash"><span id="cb13-1"><a href="#cb13-1" tabindex="-1"></a><span class="fu">cp</span> codon_table_copy.txt codons.txt <span class="co"># make a copy of codon file so we can edit this file without changing original copy</span></span>
<span id="cb13-2"><a href="#cb13-2" tabindex="-1"></a><span class="fu">head</span> codons.txt <span class="co"># double check that this copy was successful by using head</span></span>
<span id="cb13-3"><a href="#cb13-3" tabindex="-1"></a></span>
<span id="cb13-4"><a href="#cb13-4" tabindex="-1"></a><span class="fu">tr</span> a-z A-Z <span class="op"><</span> codons.txt <span class="co"># transforms all lower case alphabetical characters to upper case</span></span></code></pre></div>
<center>
<img src="Basic_Bash_Tutorial_Files/tr_example.png" />
</center>
<div align="center">
Figure 6a: Example of <code>tr</code> output, where we converted all
lower case letters to upper case.
</div>
<p></br></p>
<p><code>sed</code> is a lot more useful for editing and replacing, but
it does have somewhat of a weird syntax. The syntax is
<strong><code>s/old pattern/new pattern</code></strong>, where the old
pattern is the one you are editing, and the new pattern is what you are
replacing the old pattern with.</p>
<p><code>sed</code> is extremely powerful but can get complicated rather
quickly, so for more on <code>sed</code> and using <code>sed</code> with
regular expressions, please read this <a
href="https://www.tutorialspoint.com/unix/unix-regular-expressions.htm">Tutorials
Point link</a> and the <a
href="https://www.geeksforgeeks.org/sed-command-in-linux-unix-with-examples/">Geeks
for Geeks Link</a>.</p>
<div class="sourceCode" id="cb14"><pre
class="sourceCode bash"><code class="sourceCode bash"><span id="cb14-1"><a href="#cb14-1" tabindex="-1"></a><span class="fu">sed</span> <span class="st">'s/\t/ /g'</span> codons.txt <span class="co"># convert all \t to spaces with sed, so that now all fields or columns are separated by spaces and not tabs</span></span>
<span id="cb14-2"><a href="#cb14-2" tabindex="-1"></a></span>
<span id="cb14-3"><a href="#cb14-3" tabindex="-1"></a><span class="co">## syntax is sed 's/original_pattern/replacement_pattern/g', where "g" stands for global editing,.</span></span>
<span id="cb14-4"><a href="#cb14-4" tabindex="-1"></a><span class="co">### This means you can make these changes all throughout the file (hence it's global) rather than just making one or two edits in the file </span></span></code></pre></div>
<center>
<img src="Basic_Bash_Tutorial_Files/sed_example.png" />
</center>
<div align="center">
Figure 6b: Example of <code>sed</code> output, where we changed all tabs
to spaces.
</div>
<p></br></p>
</div>
</div>
<div id="the-end" class="section level1" number="3">
<h1><span class="header-section-number">3</span> The End</h1>
<p>Thank you for following my basic Bash scripting tutorial! I hope it
is rewarding and helpful.</p>
<p>If you’d like to get a hold of me to offer me feedback about this
tutorial, do not hestitate to reach out. My contact information is in
the <a href="#about-me">About Me</a> section.</p>
</div>
<div id="version-information" class="section level1" number="4">
<h1><span class="header-section-number">4</span> Version
Information</h1>
<div class="sourceCode" id="cb15"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb15-1"><a href="#cb15-1" tabindex="-1"></a><span class="fu">sessionInfo</span>()</span></code></pre></div>
<pre><code>## R version 4.2.2 (2022-10-31)
## Platform: x86_64-apple-darwin17.0 (64-bit)
## Running under: macOS Ventura 13.5.2
##
## Matrix products: default
## LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib
##
## locale:
## [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## loaded via a namespace (and not attached):
## [1] digest_0.6.31 R6_2.5.1 jsonlite_1.8.4 lifecycle_1.0.3 magrittr_2.0.3 evaluate_0.20 scales_1.2.1 stringi_1.7.12
## [9] cachem_1.0.7 rlang_1.1.0 cli_3.6.1 rstudioapi_0.14 jquerylib_0.1.4 bslib_0.4.2 vctrs_0.6.1 rmarkdown_2.20
## [17] tools_4.2.2 stringr_1.5.0 glue_1.6.2 munsell_0.5.0 xfun_0.40 yaml_2.3.7 fastmap_1.1.1 compiler_4.2.2
## [25] colorspace_2.1-0 htmltools_0.5.4 knitr_1.42 sass_0.4.5</code></pre>
</div>
<div id="about-me" class="section level1" number="5">
<h1><span class="header-section-number">5</span> About Me</h1>
<p>My name is Linton and my pronouns are they/them. I am currently a PhD
Student at UC Riverside in the <a href="https://ggb.ucr.edu/">Genetics,
Genomics, and Bioinformatics</a> PhD program and a member of <a
href="https://profiles.ucr.edu/app/home/profile/emmaa">Dr. Emma
Aronson’s lab</a>.</p>
<p>If you have any questions regarding this workflow and the scripts I
used, do not hesitate to contact <a
href="mailto:[email protected]?subject=Basic%20Bash%20Tutorial">me</a>.</p>
<div align="center">
<strong>Thank you so much for checking out my tutorial! Happy coding!!
</strong>
</div>
<p></br></p>
<center>
<img src="Basic_Bash_Tutorial_Files/Bash_Logo_Colored.png" />
</center>
</div>
</div>
</div>
</div>
<script>
// add bootstrap table styles to pandoc tables
function bootstrapStylePandocTables() {
$('tr.odd').parent('tbody').parent('table').addClass('table table-condensed');
}
$(document).ready(function () {
bootstrapStylePandocTables();
});
</script>
<!-- tabsets -->
<script>
$(document).ready(function () {
window.buildTabsets("TOC");
});
$(document).ready(function () {
$('.tabset-dropdown > .nav-tabs > li').click(function () {
$(this).parent().toggleClass('nav-tabs-open');
});
});
</script>
<!-- code folding -->
<script>
$(document).ready(function () {
window.initializeCodeFolding("show" === "show");
});
</script>
<script>
$(document).ready(function () {
// temporarily add toc-ignore selector to headers for the consistency with Pandoc
$('.unlisted.unnumbered').addClass('toc-ignore')
// move toc-ignore selectors from section div to header
$('div.section.toc-ignore')
.removeClass('toc-ignore')
.children('h1,h2,h3,h4,h5').addClass('toc-ignore');
// establish options
var options = {
selectors: "h1,h2,h3",
theme: "bootstrap3",
context: '.toc-content',
hashGenerator: function (text) {
return text.replace(/[.\\/?&!#<>]/g, '').replace(/\s/g, '_');
},
ignoreSelector: ".toc-ignore",
scrollTo: 0
};
options.showAndHide = true;
options.smoothScroll = true;
// tocify
var toc = $("#TOC").tocify(options).data("toc-tocify");
});
</script>
<!-- dynamically load mathjax for compatibility with self-contained -->
<script>
(function () {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
document.getElementsByTagName("head")[0].appendChild(script);
})();
</script>
</body>
</html>