This post is the continuation of A Simple Tutorial on Linux – Part-1
In the Part-1 we learned the following topics on Linux.
- Linux Operating System
- Linux Files & Process
- The Directory Structure
- Permissions
- Process
Keeping up the same pace, we will learn the following topics in the 2nd part of the Linux series.
- Shell Scripting
- Networking
- Files & Directories
- Chaining Unix Commands
- Pipes
- Filters
- Word Count Exercise
- Special System commands
- Environment variables
Writing first shell script
A shell script is a file containing a list of commands. Let’s create a simple command that prints two words:
1. Open a text editor to create a file myfirstscript.sh:
nano myfirstscript.sh
2. Write the following into the editor:
#!/bin/bash name=linux echo "hello $name world"
Note: In Unix, the extension doesn’t dictate the program to be used while executing a script. It is the first line of the script that would dictate which program to use. In the example above, the program is “/bin/bash” which is a Unix shell.
1. Press Ctrl +x to save and then “y” to exit
2. Now, by default, it would not have executable permission. You can make it executable like this:
chmod +x myfirstscript.sh
3. To run the script, use:
./myfirstscript.sh