You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -304,23 +304,23 @@ pure text. How do we save the output of an actual command like `ls -l`?
304
304
305
305
A demonstration of what doesn't work:
306
306
307
-
```
307
+
```bash
308
308
$ TEST=ls -l
309
309
```
310
310
{: .language-bash}
311
311
312
-
```
312
+
```bash
313
313
-bash: -l: command not found
314
314
```
315
315
{: .error}
316
316
317
317
What does work (we need to surround any command with `$(command)`):
318
-
```
318
+
```bash
319
319
$ TEST=$(ls -l)
320
320
$ echo$TEST
321
321
```
322
322
{: .language-bash}
323
-
```
323
+
```bash
324
324
total 90372 -rw-rw-r-- 1 jeff jeff 12534006 Jan 16 18:50 bash-lesson.tar.gz -rwxrwxr-x. 1 jeff jeff 40 Jan 1619:41 demo.sh -rw-rw-r-- 1 jeff jeff 77426528 Jan 16 18:50 dmel-all-r6.19.gtf -rw-r--r-- 1 jeff jeff 721242 Jan 25 2016 dmel_unique_protein_isoforms_fb_2016_01.tsv drwxrwxr-x. 2 jeff jeff 4096 Jan 16 19:16 fastq -rw-r--r-- 1 jeff jeff 1830516 Jan 25 2016 gene_association.fb.gz -rw-rw-r-- 1 jeff jeff 15 Jan 16 19:17 test.txt -rw-rw-r-- 1 jeff jeff 245 Jan 16 19:24 word_counts.txt
325
325
```
326
326
{: .output}
@@ -338,7 +338,7 @@ commands on every file in a directory (or other stuff of that nature).
338
338
339
339
for-loops generally have the following syntax:
340
340
341
-
```
341
+
```bash
342
342
#!/bin/bash
343
343
344
344
forVARin first second third
@@ -356,12 +356,12 @@ between `do` and `done` is performed.
356
356
357
357
Let's run the script we just wrote (I saved mine as `loop.sh`).
358
358
359
-
```
359
+
```bash
360
360
$ chmod +x loop.sh
361
361
$ ./loop.sh
362
362
```
363
363
{: .language-bash}
364
-
```
364
+
```bash
365
365
first
366
366
second
367
367
third
@@ -372,7 +372,7 @@ What if we wanted to loop over a shell variable, such as every file in the
372
372
current directory? Shell variables work perfectly in for-loops. In this
373
373
example, we'll save the result of `ls` and loop over each file:
374
374
375
-
```
375
+
```bash
376
376
#!/bin/bash
377
377
378
378
FILES=$(ls)
@@ -383,11 +383,11 @@ done
383
383
```
384
384
{: .language-bash}
385
385
386
-
```
386
+
```bash
387
387
$ ./loop.sh
388
388
```
389
389
{: .language-bash}
390
-
```
390
+
```bash
391
391
bash-lesson.tar.gz
392
392
demo.sh
393
393
dmel_unique_protein_isoforms_fb_2016_01.tsv
@@ -403,7 +403,7 @@ word_counts.txt
403
403
There's a shortcut to run on all files of a particular type, say all `.gz`
404
404
files:
405
405
406
-
```
406
+
```bash
407
407
#!/bin/bash
408
408
409
409
forVARin*.gz
@@ -412,7 +412,7 @@ do
412
412
done
413
413
```
414
414
{: .language-bash}
415
-
```
415
+
```bash
416
416
bash-lesson.tar.gz
417
417
gene_association.fb.gz
418
418
```
@@ -428,7 +428,7 @@ gene_association.fb.gz
428
428
> > ## Solution
429
429
> >
430
430
> > Create the following script in a file called `head_all.sh`
431
-
> > ```
431
+
> > ```bash
432
432
>>#!/bin/bash
433
433
>>
434
434
>>forFILEin*.fastq
@@ -450,12 +450,12 @@ gene_association.fb.gz
450
450
> whatever you want to concatenate to the beginning or end of the shell
451
451
> variable after enclosing it in `{}` characters.
452
452
>
453
-
> ```
453
+
>```bash
454
454
> FILE=stuff.txt
455
455
>echo${FILE}.example
456
456
>```
457
457
> {: .language-bash}
458
-
> ```
458
+
>```bash
459
459
> stuff.txt.example
460
460
>```
461
461
> {: .output}
@@ -466,7 +466,7 @@ gene_association.fb.gz
466
466
>>## Solution
467
467
> >
468
468
> > Create the following script in a file called `process.sh`
469
-
> > ```
469
+
>>```bash
470
470
>>#!/bin/bash
471
471
>>
472
472
>>forFILEin*
@@ -480,7 +480,7 @@ gene_association.fb.gz
480
480
>> truly only get files and not directories, we need to modify this to use the
481
481
>>`find`command to give us only files in the current directory:
482
482
>>
483
-
> > ```
483
+
>>```bash
484
484
>>#!/bin/bash
485
485
>>
486
486
>>forFILEin$(find . -max-depth 1 -type f)
@@ -506,7 +506,7 @@ gene_association.fb.gz
506
506
> Let's make an example file and give everyone permission to do everything with
0 commit comments