Skip to content

Commit 9de4d20

Browse files
committed
Minor updates for first revision
1 parent b922fb0 commit 9de4d20

21 files changed

+414
-77
lines changed

README.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## 💡 Introduction to Bash Scripting
44

5-
This is an open-source introduction to Bash scripting guide that will help you learn the basics of Bash scripting and start writing awesome Bash scripts that will help you automate your daily SysOps, DevOps, and Dev tasks. No matter if you are a DevOps/SysOps engineer, developer, or just a Linux enthusiast, you can use Bash scripts to combine different Linux commands and automate boring and repetitive daily tasks, so that you can focus on more productive and fun things.
5+
This is an open-source introduction to Bash scripting guide/ebook that will help you learn the basics of Bash scripting and start writing awesome Bash scripts that will help you automate your daily SysOps, DevOps, and Dev tasks. No matter if you are a DevOps/SysOps engineer, developer, or just a Linux enthusiast, you can use Bash scripts to combine different Linux commands and automate boring and repetitive daily tasks, so that you can focus on more productive and fun things.
66

77
The guide is suitable for anyone working as a developer, system administrator, or a DevOps engineer and wants to learn the basics of Bash scripting.
88

@@ -23,14 +23,15 @@ The first 13 chapters would be purely focused on getting some solid Bash scripti
2323
* **Bash Conditionals**
2424
* **Bash Loops**
2525
* **Bash Functions**
26-
* **Debugging and testing**
26+
* **Debugging, testing and shortcuts**
2727
* **Creating custom bash commands**
2828
* **Write your first Bash script**
2929
* **Creating an interactive menu in Bash**
3030
* **Executing BASH scripts on Multiple Remote Servers**
3131
* **Work with JSON in BASH using jq**
3232
* **Working with Cloudflare API with Bash**
3333
* **BASH Script parser to Summarize Your NGINX and Apache Access Logs**
34+
* **Sending emails with Bash and SSMTP**
3435
* **Wrap Up**
3536

3637
## 🌟 Sponsors
@@ -69,17 +70,24 @@ I think it's essential always to keep professional and surround yourself with go
6970

7071
For more information, please visit my blog at [https://bobbyiliev.com](https://bobbyiliev.com), follow me on Twitter [@bobbyiliev_](https://twitter.com/bobbyiliev_) and [YouTube](https://www.youtube.com/channel/UCQWmdHTeAO0UvaNqve9udRw).
7172

72-
## 🔥 PDF Generation
73+
## 🔥 PDF Generation Tool
7374

7475
The project uses [Ibis](https://github.com/themsaid/ibis/) developed by [Mohamed Said](https://github.com/themsaid).
7576

7677
Ibis is a PHP tool that helps you write eBooks in markdown.
7778

79+
## 🎨 Book Cover
80+
81+
The cover for this ebook was created by [Canva.com](https://www.canva.com/join/determined-cork-learn).
82+
83+
If you ever need to create a graphic, poster, invitation, logo, presentation – or anything that looks good — give Canva a go.
84+
7885
## 🔗 Links
7986

8087
- [My blog at](https://bobbyiliev.com)
8188
- [Free $100 Credit For DigitalOcean](https://m.do.co/c/2a9bba940f39)
8289
- [Join DevDojo](https://devdojo.com?ref=bobbyiliev)
90+
- [Canva](https://www.canva.com/)
8391

8492
## 🤲 Contributing
8593

content/000-about-the-author.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# About the book
22

3-
This is an open-source introduction to Bash scripting guide that will help you learn the basics of Bash scripting and start writing awesome Bash scripts that will help you automate your daily SysOps, DevOps, and Dev tasks. No matter if you are a DevOps/SysOps engineer, developer, or just a Linux enthusiast, you can use Bash scripts to combine different Linux commands and automate boring and repetitive daily tasks, so that you can focus on more productive and fun things.
3+
This is an open-source introduction to Bash scripting guide that will help you learn the basics of Bash scripting and start writing awesome Bash scripts that will help you automate your daily SysOps, DevOps, and Dev tasks. No matter if you are a DevOps/SysOps engineer, developer, or just a Linux enthusiast, you can use Bash scripts to combine different Linux commands and automate tedious and repetitive daily tasks so that you can focus on more productive and fun things.
44

55
The guide is suitable for anyone working as a developer, system administrator, or a DevOps engineer and wants to learn the basics of Bash scripting.
66

7-
The first 13 chapters would be purely focused on getting some solid Bash scripting foundations then the rest of the chapters would give you some real life examples and scripts.
7+
The first 13 chapters would be purely focused on getting some solid Bash scripting foundations, then the rest of the chapters would give you some real-life examples and scripts.
88

99
## About the author
1010

@@ -40,4 +40,16 @@ Join this developer community, and we can all learn together, build together, an
4040

4141
[Join DevDojo](https://devdojo.com?ref=bobbyiliev)
4242

43-
For more information, please visit [https://www.devdojo.com](https://www.devdojo.com?ref=bobbyiliev) or follow [@thedevdojo](https://twitter.com/thedevdojo) on Twitter.
43+
For more information, please visit [https://www.devdojo.com](https://www.devdojo.com?ref=bobbyiliev) or follow [@thedevdojo](https://twitter.com/thedevdojo) on Twitter.
44+
45+
## Ebook PDF Generation Tool
46+
47+
This ebook was generated by [Ibis](https://github.com/themsaid/ibis/) developed by [Mohamed Said](https://github.com/themsaid).
48+
49+
Ibis is a PHP tool that helps you write eBooks in markdown.
50+
51+
## Book Cover
52+
53+
The cover for this ebook was created by [Canva.com](https://www.canva.com/join/determined-cork-learn).
54+
55+
If you ever need to create a graphic, poster, invitation, logo, presentation – or anything that looks good — give Canva a go.

content/001-introduction-to-bash.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
Welcome to this Bash basics training guide! In this **bash crash course**, you will learn the **Bash basics** so you could start writing your own Bash scripts and automate your daily tasks.
44

5-
Bash is a Unix shell and command language. It is widely available on various operating systems and it is also the default command interpreter on most Linux systems.
5+
Bash is a Unix shell and command language. It is widely available on various operating systems, and it is also the default command interpreter on most Linux systems.
66

7-
Bash stands for Bourne-Again SHell. As with other shells, you can use bash interactively directly in your terminal, and also you can use Bash like any other programming language to write scripts.
7+
Bash stands for Bourne-Again SHell. As with other shells, you can use Bash interactively directly in your terminal, and also, you can use Bash like any other programming language to write scripts. This book will help you learn the basics of Bash scripting including Bash Variables, User Input, Comments, Arguments, Arrays, Conditional Expressions, Conditionals, Loops, Functions, Debugging, and testing.
88

9-
In order to write Bash scripts, you just need a UNIX terminal and a text editor like Sublime Text, VS Code, or terminal-based editor like vim or nano.
9+
In order to write Bash scripts, you just need a UNIX terminal and a text editor like Sublime Text, VS Code, or a terminal-based editor like vim or nano.

content/002-bash-structure.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Bash Structure
22

3-
Let's start by creating a new file with a `.sh` extension, as an example we could create a file called `devdojo.sh`.
3+
Let's start by creating a new file with a `.sh` extension. As an example, we could create a file called `devdojo.sh`.
44

55
To create that file, you can use the `touch` command:
66

@@ -20,4 +20,6 @@ In order to execute/run a bash script file with the bash shell interpreter, the
2020
#!/bin/bash
2121
```
2222

23-
This is also called a [Shebang](https://en.wikipedia.org/wiki/Shebang_(Unix)). All that the shebang does is to instruct the operating system to run the script with the `/bin/bash` executable.
23+
This is also called a [Shebang](https://en.wikipedia.org/wiki/Shebang_(Unix)).
24+
25+
All that the shebang does is to instruct the operating system to run the script with the `/bin/bash` executable.

content/004-bash-variables.md

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
# Bash Variables
22

3-
As with any other programming language, you can use variables in bash as well. However, there are no data types and a variable in bash can container numbers and characters.
3+
As with any other programming language, you can use variables in Bash as well. However, there are no data types, and a variable in Bash can contain numbers and characters.
44

5-
To assign a value to a variable all you need to do is use the `=` sign:
5+
To assign a value to a variable, all you need to do is use the `=` sign:
66

77
```bash
88
name="DevDojo"
99
```
1010

1111
>{notice} Note: as an important note, you can not have spaces before and after the `=` sign.
1212
13-
After that to access the variable, you have to use the `$` and reference it like this:
13+
After that, to access the variable, you have to use the `$` and reference it like this:
1414

1515
```bash
1616
echo $name
1717
```
1818

19-
Wrapping the variable name between curly brackets is not required but is considered good practice:
19+
Wrapping the variable name between curly brackets is not required but is considered good practice, and I would advise to use them whenever you can:
2020

2121
```bash
2222
echo ${name}
@@ -26,13 +26,13 @@ The above would output: `DevDojo` as this is the value of our variable.
2626

2727
Next, let's update our `devdojo.sh` script and include a variable.
2828

29-
Again, with your favorite text editor open the file:
29+
Again, with your favorite text editor, open the file:
3030

3131
```bash
3232
nano devdojo.sh
3333
```
3434

35-
And update the file so it looks like this:
35+
And update the file, so it looks like this:
3636

3737
```bash
3838
#!/bin/bash
@@ -56,6 +56,31 @@ Hi there DevDojo
5656

5757
Here is a rundown of the script:
5858

59-
* `#!/bin/bash` - first we specified our shebang
60-
* `name=DevDojo` - then we specified a variable called `name` and assigned a value to it
61-
* `echo "Hi there $name" - finally we output the content of the variable on the screen by using `echo`
59+
* `#!/bin/bash` - first, we specified our shebang
60+
* `name=DevDojo` - then we defined a variable called `name` and assigned a value to it
61+
* `echo "Hi there $name" - finally we output the content of the variable on the screen by using `echo`
62+
63+
You can also add multiple variables:
64+
65+
```bash
66+
#!/bin/bash
67+
68+
name="DevDojo"
69+
greeting="Hello"
70+
71+
echo "$greeting $name"
72+
```
73+
74+
Save it and run it again:
75+
76+
```bash
77+
./devdojo.sh
78+
```
79+
80+
You would see the following output on your screen:
81+
82+
```bash
83+
Hello DevDojo
84+
```
85+
86+
Note that you don't necessarily need to add semicolon `;` at the end of each line. It would work both ways, a bit like in JavaScript!

content/005-bash-user-input.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Bash User Input
22

3-
With the previous script, we defined a variable and we output the value of the variable on the screen with the `echo $name`.
3+
With the previous script, we defined a variable, and we output the value of the variable on the screen with the `echo $name`.
44

5-
Now let's go ahead and ask the user for input instead. To do that again open the file with your favorite text editor and update the script as follows:
5+
Now let's go ahead and ask the user for input instead. To do that again, open the file with your favorite text editor and update the script as follows:
66

77
```bash
88
#!/bin/bash
@@ -14,7 +14,7 @@ echo "Hi there $name"
1414
echo "Welcome to DevDojo!"
1515
```
1616

17-
The above will prompt the user for input, and then store that input as a string/text in a variable.
17+
The above will prompt the user for input and then store that input as a string/text in a variable.
1818

1919
We can then use the variable and print a message back to them.
2020

@@ -26,14 +26,14 @@ The output of the above script would be:
2626
./devdojo.sh
2727
```
2828

29-
* Then you would be prompted to enter your name:
29+
* Then, you would be prompted to enter your name:
3030

3131
```
3232
What is your name?
3333
Bobby
3434
```
3535

36-
* Once you've typed your name just hit enter:
36+
* Once you've typed your name, just hit enter, and you will get the following output:
3737

3838
```
3939
Hi there Bobby
@@ -51,3 +51,4 @@ echo "Hi there $name"
5151
echo "Welcome to DevDojo!"
5252
```
5353

54+
Make sure to test this out yourself as well!

content/006-bash-comments.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Bash Comments
22

3-
As with any other programming language you can add comments to your script. Comments are used to leave yourself notes through your code.
3+
As with any other programming language, you can add comments to your script. Comments are used to leave yourself notes through your code.
44

5-
To do that in bash you need to add the `#` symbol at the beginning of the line. Comments will never be rendered on the screen.
5+
To do that in Bash, you need to add the `#` symbol at the beginning of the line. Comments will never be rendered on the screen.
66

77
Here is an example of a comment:
88

@@ -24,3 +24,4 @@ echo "Hi there $name"
2424
echo "Welcome to DevDojo!"
2525
```
2626

27+
Comments are a great way to describe some of the more complex functionality directly in your scripts so that other people could find their way around your code with ease.

content/007-bash-arguments.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# Bash Arguments
22

3-
You can pass arguments to your shell script when you execute it. To pass an argument you just need to write it right after the name of your script. For example:
3+
You can pass arguments to your shell script when you execute it. To pass an argument, you just need to write it right after the name of your script. For example:
44

55
```bash
66
./devdojo.com your_argument
77
```
88

99
In the script, we can then use `$1` in order to reference the first argument that we specified.
1010

11-
If we pass a second argument it would be available as `$2` and so on.
11+
If we pass a second argument, it would be available as `$2` and so on.
1212

1313
Let's create a short script called `arguments.sh` as an example:
1414

@@ -26,7 +26,7 @@ Save the file and make it executable:
2626
chmod +x arguments.sh
2727
```
2828

29-
Then run the file and pass 3 arguments:
29+
Then run the file and pass **3** arguments:
3030

3131
```bash
3232
./arguments.sh dog catbird
@@ -40,7 +40,7 @@ Argument two is cat
4040
Argument three is bird
4141
```
4242

43-
To reference all arguments you can use `$@`:
43+
To reference all arguments, you can use `$@`:
4444

4545
```bash
4646
#!/bin/bash
@@ -62,14 +62,16 @@ All arguments: dog cat bird
6262

6363
Another thing that you need to keep in mind is that `$0` is used to reference the script itself.
6464

65-
This is a good way to create self destruct the file if you need to or just get the name of the script.
65+
This is an excellent way to create self destruct the file if you need to or just get the name of the script.
6666

6767
For example, let's create a script that prints out the name of the file and deletes the file after that:
6868

6969
```bash
7070
#!/bin/bash
7171

72-
echo "The name of the file is: $0 and it is going to be self-deleted"
72+
echo "The name of the file is: $0 and it is going to be self-deleted."
7373

7474
rm -f $0
7575
```
76+
77+
You need to be careful with the self deletion and ensure that you have your script backed up before you self-delete it.

content/008-bash-arrays.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Bash Arrays
22

3-
If you have ever done any programming you are probably already familiar with arrays.
3+
If you have ever done any programming, you are probably already familiar with arrays.
44

5-
But just in case that you are not a developer, unlike variables, arrays can hold several values under one name.
5+
But just in case you are not a developer, the main thing that you need to know is that unlike variables, arrays can hold several values under one name.
66

77
You can initialize an array by assigning values devided by space and enclosed in `()`. Example:
88

@@ -30,4 +30,6 @@ echo ${my_array[-1]}
3030

3131
```bash
3232
echo ${my_array[@]}
33-
```
33+
```
34+
35+
Make sure to test this and practice it at your end with different values.

content/009-bash-conditional-expressions.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Bash Conditional Expressions
22

3-
In computer science, conditional statements, conditional expressions and conditional constructs are features of a programming language, which perform different computations or actions depending on whether a programmer-specified boolean condition evaluates to true or false.
3+
In computer science, conditional statements, conditional expressions, and conditional constructs are features of a programming language, which perform different computations or actions depending on whether a programmer-specified boolean condition evaluates to true or false.
44

5-
In bash conditional expressions are used by the `[[` compound command and the `[` builtin commands to test file attributes and perform string and arithmetic comparisons.
5+
In Bash, conditional expressions are used by the `[[` compound command and the `[`built-in commands to test file attributes and perform string and arithmetic comparisons.
66

7-
Here is a list with the most popular bash conditional expressions, you do not have to memorize them by hard, you can simply bookmark this page and reference back to this list whenever you need it!
7+
Here is a list of the most popular Bash conditional expressions. You do not have to memorize them by heart. You can simply refer back to this list whenever you need it!
88

99
## File expressions
1010

0 commit comments

Comments
 (0)