Introduction to Bash Scripting
Chapters
If you are looking for a beginer's course for Bash scripting, This course is very well for you. I've covered some of the most important topics to get you started. Course contents include
- Welcome message [Free]
- What is Bash
- Command line shortcuts and tricks
- Getting started with Bash profiles
- Bash Expansions
- Command Redirection and Piping
- Using Echo and PrintF and how to preventing command expansion
- Understanding local and environment variables
- Bash script syntax
- A basic Bash script
- Working with numbers and operators
- Working with arrays
- Controlling output with awk, grep and cut commands. How to use basic bash color themes with your output.
- Working with here document and files
- Flow control statements and loops
- Introduction to functions
- Interacting with user
- Closing note
I hope that you will learn heaps from this course, please leave your feedback and improvement suggestions.
Author: Subject Coach
Added on: 23rd Jan 2015
Please get in touch with your teacher or tutor in case you have a question related to this lesson
None just yet!
Bash scripts as you know by now, are group of statements that you will write in a file and execute them altogether. you can do similar stuff by typing commands on command line, however! idea of scripts is that, you can reuse what you have done in future, and give yourself flexibility to add or remove functionaility from the script.
When writing scripts you will use terminal window and text editor such as VI or nano. Let's start writing our first script. open cat.sh with nano to edit. .sh part of the file name tells us that this is a bash script file.
We will now begin with HashBang followed by path to bash, this will be first line for our script. then we will add a comment, that tells us what this script does. In general commenting your code is a good practice. we will add printF to print two new line characters. Now we will use cat command to output contents of bashRC file. Then we will again print a couple of new line characters. I will now press CTRL+O to save this file and CTRL+X to exit.
we can now execute this script by using bash interpreter. We can also make use of our HashBang line. I'll make my script executable by current user. Then I will just have to type ./cat.sh to run my script. We need ./ to run our script because current working directory is not part of PATH environment. If I put my current directory path in our environment PATH variable then I will not need ./ to run my script.
In next chapter, we will learn to work with numbers and how we can compare values.