Table of Contents
Chapter 3. The Bash environment..................................................................................................................29
3.1. Shell initialization files...................................................................................................................29
3.1.1. System−wide configuration files...........................................................................................29
3.1.2. Individual user configuration files........................................................................................31
3.1.3. Changing shell configuration files........................................................................................33
3.2. Variables.........................................................................................................................................34
3.2.1. Types of variables.................................................................................................................34
3.2.2. Creating variables..................................................................................................................37
3.2.3. Exporting variables................................................................................................................38
3.2.4. Reserved variables.................................................................................................................39
3.2.5. Special parameters.................................................................................................................41
3.2.6. Script recycling with variables..............................................................................................43
3.3. Quoting characters..........................................................................................................................44
3.3.1. Why?.....................................................................................................................................44
3.3.2. Escape characters..................................................................................................................45
3.3.3. Single quotes.........................................................................................................................45
3.3.4. Double quotes........................................................................................................................45
3.3.5. ANSI−C quoting...................................................................................................................46
3.3.6. Locales...................................................................................................................................46
3.4. Shell expansion...............................................................................................................................46
3.4.1. General..................................................................................................................................46
3.4.2. Brace expansion....................................................................................................................46
3.4.3. Tilde expansion.....................................................................................................................47
3.4.4. Shell parameter and variable expansion................................................................................47
3.4.5. Command substitution...........................................................................................................48
3.4.6. Arithmetic expansion............................................................................................................49
3.4.7. Process substitution...............................................................................................................50
3.4.8. Word splitting........................................................................................................................50
3.4.9. File name expansion..............................................................................................................51
3.5. Aliases.............................................................................................................................................51
3.5.1. What are aliases?...................................................................................................................51
3.5.2. Creating and removing aliases..............................................................................................52
3.6. More Bash options..........................................................................................................................53
3.6.1. Displaying options.................................................................................................................53
3.6.2. Changing options...................................................................................................................54
3.7. Summary.........................................................................................................................................55
3.8. Exercises.........................................................................................................................................55
Chapter 4. Regular expressions.......................................................................................................................56
4.1. Regular expressions........................................................................................................................56
4.1.1. What are regular expressions?...............................................................................................56
4.1.2. Regular expression metacharacters.......................................................................................56
4.1.3. Basic versus extended regular expressions...........................................................................57
4.2. Examples using grep.......................................................................................................................57
4.2.1. What is grep?.........................................................................................................................57
4.2.2. Grep and regular expressions................................................................................................58
4.3. Pattern matching using Bash features.............................................................................................60
4.3.1. Character ranges....................................................................................................................60
Bash Guide for Beginners
ii