Bourne Shell Scripting/Appendix C: Quick Reference

This final section provides a fast lookup reference for the materials in this document. It is a collection of thumbnail examples and rules that will be cryptic if you haven't read through the text.

IF statement
The if statement executes the command between  and. If the command returns not 0 then the commands between  and   are executed - otherwise the command between   and.

Test Syntax Variations
Most test commands can be written using more than one syntax. Mastering and consistently using one form may be a programming best-practice, and may be a more efficient use of overall time.

String Tests
String Tests are performed by the  command. See  for more details. To make scripts look more like other programming languages the synonym  was defined which does exactly the same as.

Arithmetic tests
simple arithmetics can be performed with the  for more complex arithmetics the   command exists. See  for more details. Note that for  command variables don't need to be prefixed with '$' and the statement need to be one argument, use   when there are spaces inside the argument. Like with  a synonym -   - was defined to make shell scripts look more like ordinary programs.

Boolean tests
Boolean arithmetic is performed by a set of operators. It is important to note then the operators execute programs and compare the result codes. Because boolean operators are often combined with  command a unifications was created in the form of.

Loop statements
There are "break" and "continue" commands that allow you to exit or skip to the end of loops as the need arises.

Instead of [] we can use test. [] requires space after and before the brackets and there should be spaces between arguments.

Credit
This content was originally from http://www.vectorsite.net/tsshell.html and was originally in the public domain.