Components of a Shell Program
This module introduced you to the programming concepts that are used in creating a shell script. If you have programmed before, these concepts may be familiar to you, though their application in shell scripts may differ from other situations.
Now that you understand these concepts, you are ready to dive into creating your first real shell script.
Terms and concepts
This module introduced you to the following terms and concepts:
- Built-in commands
- External commands
- Managing input and output in a script
- A shell script as a command line macro
- Tests within
- Variables in shell scripts
- Control and looping structures
- Regular expressions
Linux Shell Scripting
Basically, a shell script is a text file with Unix commands in it.
Shell scripts usually begin with a #! and a shell name
If the shell script does not begin with #!/bin/sh, the user's current shell environment will be used
Any Unix command can go in a shell script: Commands are executed in order or in the flow determined by control statements.
Different shells have different control structures
- The #! line is very important
- We will write shell scripts with the Bourne shell (sh)
Why write shell scripts?
- To avoid repetition: If you do a sequence of steps with standard Unix commands over and over,
why not condense those commands and enable repetition with just one command?
- To automate difficult tasks: Many commands have subtle and difficult options that you do not want to figure out or remember every time.
It is possible to create shell scripts that are far more interactive and involving than the regular
- Press 1 to continue,
- Press 2 to exit
type menu systems that are usually passed off as interactive shell scripts.
The shell can do much more than is regularly exploited, and although the shell is far from being the perfect language for game development,
I hope this recipe will inspire more creative uses of shell scripts and particularly the newer features available in the bash shell (such as arrays) and in the GNU environment (like sleep being able to perform sub-second sleeps, without which this game is much less fun to play).