Maybe most of the readers of this blog do already know about shell scripts, and maybe they know even more than me (which is not difficult), but for those who does not know about it, I will write a little about shell scripts.
A shell script is a sequence of commands -For those coming from DOS is like a .bat file- this command will execute in the sequence they are entered, unless loops, if, do, for, or any other commands like those are used.
Writing the script
Lets go with the classic example, of "Hello World"
First just use your favorite text editor, (do not use a word processor), and write this inside.
#!/bin/sh clear echo "Hello World"
lets say you named this file, myfirstscript.sh, you can name it almost anything you want, but try to use a comprehensive name, and use the .sh extension, for better human reading.
Making it executable
Now we need to tell Linux that this is an executable file, so the operating system may know how to treat with it, to do that execute
chmod +x myfirstscript.sh
Explaining the script a little
The first like tells Linux which interpreter to use, there are a lot of different interpreters, some are:
you can learn more on Wikipedia
Running the script
To run it just go to the directory where it is saved and run:
Remember to use
./ when you are on the same directory or it will not execute, also you can save it in a directory which is included in you path, or include its directory in you path variable.
I will continue with this topic later.