From aa171cbdf8f095e0ef83c0b4c5ea4ef1bc05be4b Mon Sep 17 00:00:00 2001 From: Dave Kerr Date: Tue, 26 Apr 2022 11:05:19 +0800 Subject: [PATCH] docs: refine shell script essentials --- .../18-shell-script-essentials/index.md | 37 +++++++++---------- samples/data/history.txt | 9 +++++ 2 files changed, 27 insertions(+), 19 deletions(-) create mode 100644 samples/data/history.txt diff --git a/docs/04-shell-scripting/18-shell-script-essentials/index.md b/docs/04-shell-scripting/18-shell-script-essentials/index.md index b0e9fbff..ae5350a8 100644 --- a/docs/04-shell-scripting/18-shell-script-essentials/index.md +++ b/docs/04-shell-scripting/18-shell-script-essentials/index.md @@ -3,9 +3,9 @@ title: 'Shell Script Essentials' slug: '/part-3-manipulating-text/shell-script-essentials/' --- -First we're going to look at how to write shell scripts as well as the different ways to execute them. We'll look at how shell script files should be structured and how to use 'shebangs' to define how a shell script will run. +In this chapter we're going to look at how to write shell scripts and the different ways we can execute them. We'll look at how shell script files should be structured and how to use 'shebangs' to define how a shell script will run. -These will be essential techniques to have as a foundation for building your own scripts. Even if you are familiar with shell scripts I would suggest skimming this chapter to make sure you understand each of the concepts, particularly the later section where we talk about using the `env` command in shebangs. +We'll learn the essential techniques that will be help you build your own scripts. Even if you are familiar with shell scripts I would suggest skimming this chapter to make sure you understand each of the concepts, particularly the later section where we talk about using the `env` command in shebangs. ## What is a Shell Script? @@ -19,7 +19,7 @@ Let's create a simple shell script that shows us our most commonly used shell co Almost every command that is needed to build the script has been discussed in the book already, so it shouldn't be too unfamiliar. But I'll still break it down blow-by-blow to help us understand it. -As we go through this section of the book we're going to extend this script and make it more useful! +As we go through this section of the book, we're going to extend this script and make it more useful! ### The 'common' Command @@ -29,7 +29,7 @@ We should be able to do this using techniques we've seen so far. We'll do it lik 1. Read a large number of commands from the history 2. Sort the commands, then count the number of duplicates -3. Sort the commands, by the number of duplicates (i.e. ordering by 'most commonly used') +3. Sort this list showing the most commonly run commands first 4. Print the results to the screen. Let's get started! @@ -53,19 +53,21 @@ vi ~/scripts.sh ``` I have called the script `common.v1.sh` rather than `common.sh` because in each chapter of this section we are going to improve upon the script and change the version number. So in later chapters we will create `common.v2.sh`, `common.v3.sh` and so on. -These commands should be familiar. The `mkdir` command creates a directory. The `-p` (create parent directories if needed) flag stops the command from returning an error if the directory already exist. +These commands should be familiar. The `mkdir` command creates a directory. The `-p` (create parent directories if needed) flag stops the command from returning an error if the directory already exists. -The `touch` command creates an empty file with the given name. Finally, I open the file in an editor. I am using Vim, but you can open this file in any editor you like. +The `touch` command creates an empty file with the given name. Finally, I open the file in an editor. I am using Vim, but you can open this file in any editor you like. If you would like to see how to use Vim you can also jump to [Chapter 32 - A Vim Crash Course](../../06-advanced-techniques/32-a-vim-crash-course/index.mdx). -Before we build the script, let's quickly talk about _comments_. +Before we run the script, let's quickly talk about _comments_. ## Comments