Skip to content

Commit 725f9dc

Browse files
added more exercises
1 parent 1e2c601 commit 725f9dc

File tree

4 files changed

+39
-4
lines changed

4 files changed

+39
-4
lines changed

assorted-text-processing-tools.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,17 @@
543543
tea
544544

545545
$ rm xx0?
546+
</code></pre><p><strong>21)</strong> Write a generic solution that transposes comma delimited data. Example input/output is shown below. You can use any tool(s) presented in this book.<pre><code class=language-bash>$ cat scores.csv
547+
Name,Maths,Physics,Chemistry
548+
Ith,100,100,100
549+
Cy,97,98,95
550+
Lin,78,83,80
551+
552+
# ???
553+
Name,Ith,Cy,Lin
554+
Maths,100,97,78
555+
Physics,100,98,83
556+
Chemistry,100,95,80
546557
</code></pre></main><nav class=nav-wrapper aria-label="Page navigation"><a rel=prev href=comparing-files.html class="mobile-nav-chapters previous"title="Previous chapter"aria-label="Previous chapter"aria-keyshortcuts=Left> <i class="fa fa-angle-left"></i> </a><a rel=next href=shell-scripting.html class="mobile-nav-chapters next"title="Next chapter"aria-label="Next chapter"aria-keyshortcuts=Right> <i class="fa fa-angle-right"></i> </a><div style="clear: both"></div></nav></div></div><nav class=nav-wide-wrapper aria-label="Page navigation"><a rel=prev href=comparing-files.html class="nav-chapters previous"title="Previous chapter"aria-label="Previous chapter"aria-keyshortcuts=Left> <i class="fa fa-angle-left"></i> </a><a rel=next href=shell-scripting.html class="nav-chapters next"title="Next chapter"aria-label="Next chapter"aria-keyshortcuts=Right> <i class="fa fa-angle-right"></i> </a></nav></div><script>
547558
window.playground_copyable = true;
548559
</script><script src=elasticlunr.min.js charset=utf-8></script><script src=mark.min.js charset=utf-8></script><script src=searcher.js charset=utf-8></script><script src=clipboard.min.js charset=utf-8></script><script src=highlight.js charset=utf-8></script><script src=book.js charset=utf-8></script><script src=sidebar.js></script>

searchindex.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

searchindex.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

shell-scripting.html

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@
549549

550550
greeting = 'hello world'
551551
echo "$greeting"
552-
</code></pre><p>Here's how <code>shellcheck</code> reports the issue:<pre><code class=language-bash>$ shellcheck bad_script.sh
552+
</code></pre><p>Here's how <code>shellcheck</code> reports the issue:<pre><code class=language-nohighlight>$ shellcheck bad_script.sh
553553

554554
In bad_script.sh line 3:
555555
greeting = 'hello world'
@@ -700,6 +700,30 @@
700700
$ bash loop.sh items_1.txt items_2.txt
701701
number of lines in 'items_1.txt' is: 3
702702
number of lines in 'items_2.txt' is: 5
703-
</code></pre></main><nav class=nav-wrapper aria-label="Page navigation"><a rel=prev href=assorted-text-processing-tools.html class="mobile-nav-chapters previous"title="Previous chapter"aria-label="Previous chapter"aria-keyshortcuts=Left> <i class="fa fa-angle-left"></i> </a><a rel=next href=shell-customization.html class="mobile-nav-chapters next"title="Next chapter"aria-label="Next chapter"aria-keyshortcuts=Right> <i class="fa fa-angle-right"></i> </a><div style="clear: both"></div></nav></div></div><nav class=nav-wide-wrapper aria-label="Page navigation"><a rel=prev href=assorted-text-processing-tools.html class="nav-chapters previous"title="Previous chapter"aria-label="Previous chapter"aria-keyshortcuts=Left> <i class="fa fa-angle-left"></i> </a><a rel=next href=shell-customization.html class="nav-chapters next"title="Next chapter"aria-label="Next chapter"aria-keyshortcuts=Right> <i class="fa fa-angle-right"></i> </a></nav></div><script>
703+
</code></pre><p><strong>21)</strong> Write a shell script named <code>read_file.sh</code> that reads a file line by line to be passed as argument to the <code>paste -sd,</code> command. Can you also write a solution using the <code>xargs</code> command instead of a script?<pre><code class=language-bash>$ printf 'apple\nbanana\ncherry\n' > items_1.txt
704+
$ printf 'dragon\nowl\nunicorn\ntroll\ncentaur\n' > items_2.txt
705+
$ printf 'items_1.txt\nitems_2.txt\n' > list.txt
706+
707+
$ bash read_file.sh list.txt
708+
apple,banana,cherry
709+
dragon,owl,unicorn,troll,centaur
710+
711+
$ xargs # ???
712+
apple,banana,cherry
713+
dragon,owl,unicorn,troll,centaur
714+
</code></pre><p><strong>22)</strong> Write a function named <code>add_path</code> which prefixes the path of the current working directory to the arguments it receives and displays the results. Examples are shown below.<pre><code class=language-bash>$ add_path() # ???
715+
716+
$ cd
717+
$ pwd
718+
/home/learnbyexample
719+
$ add_path ip.txt report.log
720+
/home/learnbyexample/ip.txt /home/learnbyexample/report.log
721+
722+
$ cd cli-computing
723+
$ pwd
724+
/home/learnbyexample/cli-computing
725+
$ add_path f1
726+
/home/learnbyexample/cli-computing/f1
727+
</code></pre><p><strong>23)</strong> What do the options <code>bash -x</code> and <code>bash -v</code> do?<p><strong>24)</strong> What is <code>shellcheck</code> and when would you use it?</main><nav class=nav-wrapper aria-label="Page navigation"><a rel=prev href=assorted-text-processing-tools.html class="mobile-nav-chapters previous"title="Previous chapter"aria-label="Previous chapter"aria-keyshortcuts=Left> <i class="fa fa-angle-left"></i> </a><a rel=next href=shell-customization.html class="mobile-nav-chapters next"title="Next chapter"aria-label="Next chapter"aria-keyshortcuts=Right> <i class="fa fa-angle-right"></i> </a><div style="clear: both"></div></nav></div></div><nav class=nav-wide-wrapper aria-label="Page navigation"><a rel=prev href=assorted-text-processing-tools.html class="nav-chapters previous"title="Previous chapter"aria-label="Previous chapter"aria-keyshortcuts=Left> <i class="fa fa-angle-left"></i> </a><a rel=next href=shell-customization.html class="nav-chapters next"title="Next chapter"aria-label="Next chapter"aria-keyshortcuts=Right> <i class="fa fa-angle-right"></i> </a></nav></div><script>
704728
window.playground_copyable = true;
705729
</script><script src=elasticlunr.min.js charset=utf-8></script><script src=mark.min.js charset=utf-8></script><script src=searcher.js charset=utf-8></script><script src=clipboard.min.js charset=utf-8></script><script src=highlight.js charset=utf-8></script><script src=book.js charset=utf-8></script><script src=sidebar.js></script>

0 commit comments

Comments
 (0)