POSIX shell script features
Features required for the POSIX shell script include:
- Running commands convenient syntax for running commands, including other programs, specifying arguments, environment variables, working directories, permissions masking, and other properties.
- Variables that can be set to any string value, including manipulating process environment variables, and that can be expanded on the command line.
- Arithmetic expansion for performing integer-based arithmetic on variables and numbers.
- Control structures for executing code depending on the outcome of another command (if), including a specially-designed test or [ command, and repeating code until a condition is true (while).
- Aliases as a way to abbreviate long command lines as a single word for convenience.
- Functions to allow defining blocks of code as new commands for the purposes of the running script or interactive session.
- Input and output redirection to specify input sources and output destinations for programs run in the shell.
- Pipes to direct the output of one command to become the input of another.
- Argument list through which code can iterate using a for loop.
- Parameter expansion a means of switching between or transforming string values in assignments or command arguments.
- Pattern matching in the form of classic Unix globs.
- Process management in running jobs in the background, and waiting for them to complete at the desired point.
- Compound commands to treat a group of commands as one, optionally running it in a subshell environment (subprocess).
- Reading lines of input data including breaking them down into fields with a defined separator character.
- Formatted strings such as the C printf(3) function in the stdio C programming language library.
- Command substitution to use the output of a command as a variable, as part of a test, or as an argument to another command.
These features are either part of the Shell scripting language itself, or available in the POSIX-specified programs that it calls. In a sense, your shell scripts are only limited by the programs you can run with them.
By calling the grep program, for example, you can select input lines using regular expressions, even if your Shell scripting language does not itself support regular expressions. We will cover some of these essential commands in this book, even though they are not technically part of the GNU Bash distribution.
All the these features mean you can get a lot done in your Bash program even if you just use POSIX features, and your script might then run on other shells, such as dash, without much modification. All of the features are discussed in this book.