Components of Shell Script
The components of a shell script are:
- Command within the shell: variable
- Test a true/false condition: looping structure
- Accepts keyboard input: if statement
- Named value: external command
- Any command executed by the shell: built-in command
- Repeats blocks of commands: read command
List of Commands
The basic concept of a shell script is a list of commands, which are listed in the order of execution.
A good shell script will have comments, preceded by a pound sign or hash mark, #, describing the steps.
There are conditional tests, such as value A is greater than value B, loops allowing us to go through massive amounts of data, files to read and store data, variables to read and store data, and the script may include functions. We are going to write a lot of scripts in the next several hundred pages, and we should always start with a clear goal in mind.
With a clear goal, we have a specific purpose for the script, and we have a set of expected results. We will also hit on some tips, tricks, and, of course, the gotchas in solving a challenge one way as opposed to another to get the same result. All techniques are not created equal. Shell scripts and functions are both interpreted. This means they are not compiled. Both shell scripts and functions are ASCII text that is read by the shell command interpreter. When we execute a shell script, or function, a command interpreter goes through the ASCII text line-by-line, loop-by-loop, test-by-test, and executes each statement as each line is reached from the top to the bottom.