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
Copy file name to clipboardExpand all lines: README.md
+11-3Lines changed: 11 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
## 💡 Introduction to Bash Scripting
4
4
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.
6
6
7
7
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.
8
8
@@ -23,14 +23,15 @@ The first 13 chapters would be purely focused on getting some solid Bash scripti
23
23
***Bash Conditionals**
24
24
***Bash Loops**
25
25
***Bash Functions**
26
-
***Debuggingand testing**
26
+
***Debugging, testing and shortcuts**
27
27
***Creating custom bash commands**
28
28
***Write your first Bash script**
29
29
***Creating an interactive menu in Bash**
30
30
***Executing BASH scripts on Multiple Remote Servers**
31
31
***Work with JSON in BASH using jq**
32
32
***Working with Cloudflare API with Bash**
33
33
***BASH Script parser to Summarize Your NGINX and Apache Access Logs**
34
+
***Sending emails with Bash and SSMTP**
34
35
***Wrap Up**
35
36
36
37
## 🌟 Sponsors
@@ -69,17 +70,24 @@ I think it's essential always to keep professional and surround yourself with go
69
70
70
71
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).
71
72
72
-
## 🔥 PDF Generation
73
+
## 🔥 PDF Generation Tool
73
74
74
75
The project uses [Ibis](https://github.com/themsaid/ibis/) developed by [Mohamed Said](https://github.com/themsaid).
75
76
76
77
Ibis is a PHP tool that helps you write eBooks in markdown.
77
78
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
+
78
85
## 🔗 Links
79
86
80
87
-[My blog at](https://bobbyiliev.com)
81
88
-[Free $100 Credit For DigitalOcean](https://m.do.co/c/2a9bba940f39)
Copy file name to clipboardExpand all lines: content/000-about-the-author.md
+15-3Lines changed: 15 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,10 @@
1
1
# About the book
2
2
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.
4
4
5
5
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.
6
6
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 reallife 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.
8
8
9
9
## About the author
10
10
@@ -40,4 +40,16 @@ Join this developer community, and we can all learn together, build together, an
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.
Copy file name to clipboardExpand all lines: content/001-introduction-to-bash.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,8 +2,8 @@
2
2
3
3
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.
4
4
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.
6
6
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.
8
8
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.
Copy file name to clipboardExpand all lines: content/002-bash-structure.md
+4-2Lines changed: 4 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Bash Structure
2
2
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`.
4
4
5
5
To create that file, you can use the `touch` command:
6
6
@@ -20,4 +20,6 @@ In order to execute/run a bash script file with the bash shell interpreter, the
20
20
#!/bin/bash
21
21
```
22
22
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.
Copy file name to clipboardExpand all lines: content/004-bash-variables.md
+34-9Lines changed: 34 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,22 +1,22 @@
1
1
# Bash Variables
2
2
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.
4
4
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:
6
6
7
7
```bash
8
8
name="DevDojo"
9
9
```
10
10
11
11
>{notice} Note: as an important note, you can not have spaces before and after the `=` sign.
12
12
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:
14
14
15
15
```bash
16
16
echo$name
17
17
```
18
18
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:
20
20
21
21
```bash
22
22
echo${name}
@@ -26,13 +26,13 @@ The above would output: `DevDojo` as this is the value of our variable.
26
26
27
27
Next, let's update our `devdojo.sh` script and include a variable.
28
28
29
-
Again, with your favorite text editor open the file:
29
+
Again, with your favorite text editor, open the file:
30
30
31
31
```bash
32
32
nano devdojo.sh
33
33
```
34
34
35
-
And update the file so it looks like this:
35
+
And update the file, so it looks like this:
36
36
37
37
```bash
38
38
#!/bin/bash
@@ -56,6 +56,31 @@ Hi there DevDojo
56
56
57
57
Here is a rundown of the script:
58
58
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!
Copy file name to clipboardExpand all lines: content/005-bash-user-input.md
+6-5Lines changed: 6 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,8 @@
1
1
# Bash User Input
2
2
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`.
4
4
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:
6
6
7
7
```bash
8
8
#!/bin/bash
@@ -14,7 +14,7 @@ echo "Hi there $name"
14
14
echo"Welcome to DevDojo!"
15
15
```
16
16
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.
18
18
19
19
We can then use the variable and print a message back to them.
20
20
@@ -26,14 +26,14 @@ The output of the above script would be:
26
26
./devdojo.sh
27
27
```
28
28
29
-
* Then you would be prompted to enter your name:
29
+
* Then, you would be prompted to enter your name:
30
30
31
31
```
32
32
What is your name?
33
33
Bobby
34
34
```
35
35
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:
Copy file name to clipboardExpand all lines: content/006-bash-comments.md
+3-2Lines changed: 3 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,8 @@
1
1
# Bash Comments
2
2
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.
4
4
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.
6
6
7
7
Here is an example of a comment:
8
8
@@ -24,3 +24,4 @@ echo "Hi there $name"
24
24
echo"Welcome to DevDojo!"
25
25
```
26
26
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.
Copy file name to clipboardExpand all lines: content/007-bash-arguments.md
+8-6Lines changed: 8 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,14 +1,14 @@
1
1
# Bash Arguments
2
2
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:
4
4
5
5
```bash
6
6
./devdojo.com your_argument
7
7
```
8
8
9
9
In the script, we can then use `$1` in order to reference the first argument that we specified.
10
10
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.
12
12
13
13
Let's create a short script called `arguments.sh` as an example:
14
14
@@ -26,7 +26,7 @@ Save the file and make it executable:
26
26
chmod +x arguments.sh
27
27
```
28
28
29
-
Then run the file and pass 3 arguments:
29
+
Then run the file and pass **3** arguments:
30
30
31
31
```bash
32
32
./arguments.sh dog catbird
@@ -40,7 +40,7 @@ Argument two is cat
40
40
Argument three is bird
41
41
```
42
42
43
-
To reference all arguments you can use `$@`:
43
+
To reference all arguments, you can use `$@`:
44
44
45
45
```bash
46
46
#!/bin/bash
@@ -62,14 +62,16 @@ All arguments: dog cat bird
62
62
63
63
Another thing that you need to keep in mind is that `$0` is used to reference the script itself.
64
64
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.
66
66
67
67
For example, let's create a script that prints out the name of the file and deletes the file after that:
68
68
69
69
```bash
70
70
#!/bin/bash
71
71
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."
73
73
74
74
rm -f $0
75
75
```
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.
Copy file name to clipboardExpand all lines: content/008-bash-arrays.md
+5-3Lines changed: 5 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,8 @@
1
1
# Bash Arrays
2
2
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.
4
4
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.
6
6
7
7
You can initialize an array by assigning values devided by space and enclosed in `()`. Example:
8
8
@@ -30,4 +30,6 @@ echo ${my_array[-1]}
30
30
31
31
```bash
32
32
echo${my_array[@]}
33
-
```
33
+
```
34
+
35
+
Make sure to test this and practice it at your end with different values.
Copy file name to clipboardExpand all lines: content/009-bash-conditional-expressions.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,10 @@
1
1
# Bash Conditional Expressions
2
2
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.
4
4
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.
6
6
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!
0 commit comments