A Background On Shell Scripts
A brief review on the meaning of shell scripts
Shell scripts are integral to the functioning of Linux systems and are used to perform a variety of tasks. Some shell scripts set up the configuration for running a series of commands or setting up database parameters. Others contain the code to perform automated backups. The dotfiles are examples of shell scripts. Shell scripts may contain loops to execute sets of commands (called blocks) over and over again, 'if' statements that execute blocks conditionally, and so on. Although a shell script may have any extension, it should comply with the Linux convention and end with an extension that points to the shell that it was written for - '.sh' for bourne shell, .csh for c shell and so on.
Shell scripts are text files that the OS executes. After a shell script is written and saved, the chmod command should be used to give the appropriate users execute permission and run the script from the command line. Text editing programs like vi and emacs may be used to create, modify, and save shell scripts and other text files. In this chapter, we will first write a shell script that performs incremental backups using rsync. In the process, we will learn more about the structure and syntax of shell scripts in general. Afterwards, we will learn to write the script using the vi editor. This chapter also contains an introduction to the emacs editor.
Be aware that a subshell is created for the execution of a shell script. This subshell inherits all the shell environment variables, including the current directory, but any changes made to the environment in the script itself are lost when the script terminates. Such changes will have to be made using the 'export' command or the script should be run prefixed with a dot and a space (. <Script_name>)