Log In
Or create an account ->
Imperial Library
Home
About
News
Upload
Forum
Help
Login/SignUp
Index
Cover
Title
Copyright
Dedication
Contents at a Glance
Contents
About the Authors
Acknowledgments
Chapter 1: Hello, World: Your First Shell Program
The Code
The File
The Naming of Scripts
Selecting a Directory for the Script
Creating the File and Running the Script
Choosing and Using a Text Editor
Building a Better “Hello, World!”
Summary
Commands
Concepts
Variables
Exercises
Chapter 2: Input, Output, and Throughput
Parameter and Variables
Positional Parameters
Special*@#0$?_!- Parameters
Variables
Arguments and Options
echo, and Why You Should Avoid It
printf: Formatting and Printing Data
Escape Sequences
Format Specifiers
Width Specification
Printing to a Variable
Line Continuation
Standard Input /Output Streams and Redirection
Redirection: >, >>, and <
Reading Input
Pipelines
Command Substitution
Summary
Commands
Concepts
Exercises
Chapter 3: Looping and Branching
Exit Status
Testing an Expression
test, a.k.a. [ … ]
[[ … ]]: Evaluate an Expression
(( … )): Evaluate an Arithmetic Expression
Conditional Execution
if
Conditional Operators, & and ||
case
Looping
while
until
for
break
continue
Summary
Commands
Concepts
Exercises
Chapter 4: Command-Line Parsing and Expansion
Quoting
Brace Expansion
Tilde Expansion
Parameter and Variable Expansion
Arithmetic Expansion
Command Substitution
Word Splitting
Pathname Expansion
Process Substitution
Parsing Options
Summary
Commands
Exercises
Chapter 5: Parameters and Variables
The Naming of Variables
The Scope of a Variable: Can You See It from Here?
Shell Variables
Parameter Expansion
Bourne Shell
POSIX Shell
Bash
Bash-4.0
Positional Parameters
Arrays
Integer-Indexed Arrays
Associative Arrays
Summary
Commands
Concepts
Chapter 6: Shell Functions
Definition Syntax
Compound Commands
Getting Results
Set Different Exit Codes
Print the Result
Place Results in One or More Variables
Function Libraries
Using Functions from Libraries
Sample Script
Summary
Commands
Exercises
Chapter 7: String Manipulation
Concatenation
Repeat Character to a Given Length
Processing Character by Character
Reversal
Case Conversion
Comparing Contents Without Regard to Case
Check for Valid Variable Name
Insert One String into Another
Examples
Overlay
Examples
Trim Unwanted Characters
Examples
Index
Summary
Commands
Functions
Exercises
Chapter 8: File Operations and Commands
Reading a File
External Commands
cat
head
touch
ls
cut
wc
Regular Expressions
grep
sed
awk
File Name Expansion Options
nullglob
failglob
dotglob
extglob
nocaseglob
globstar
Summary
Shell Options
External Commands
Exercises
Chapter 9: Reserved Words and Built-In Commands
help, Display Information About Built-In Commands
time, Print Time Taken for Execution of a Command
read, Read a Line from an Input Stream
-r, Read Backslashes Literally
-e, Get Input with the readline Library
-a, Read Words into an Array
-d DELIM, Read Until DELIM Instead of a Newline
-n NUM, Read a Maximum of NUM Characters
-s, Do Not Echo Input Coming from a Terminal
-p PROMPT:, Output PROMPT Without a Trailing Newline
-t TIMEOUT, Only Wait TIMEOUT Seconds for Complete Input
-u FD: Read from File Descriptor FD Instead of the Standard Input
-i TEXT, Use TEXT as the Initial Text for Readline
eval, Expand Arguments and Execute Resulting Command
Poor Man’s Arrays
Setting Multiple Variables from One Command
type, Display Information About Commands
builtin, Execute a Built-In Command
command, Execute a Command or Display Information About Commands
pwd, Print the Current Working Directory
unalias, Remove One or More Aliases
Deprecated Built-Ins
Dynamically Loadable Built-Ins
Summary
Commands and Reserved Words
Deprecated Commands
Exercise
Chapter 10: Writing Bug-Free Scripts and Debugging the Rest
Prevention Is Better Than Cure
Structure Your Programs
Document Your Code
Format Your Code Consistently
The K.I.S.S. Principle
Test as You Go
Debugging a Script
Summary
Exercises
Chapter 11: Programming for the Command Line
Manipulating the Directory Stack
cd
pd
cdm
menu
Filesystem Functions
l
lsr
cp, mv
md
Miscellaneous Functions
pr1
calc
Managing Man Pages
sman
sus
k
Games
The fifteen Puzzle
Summary
Exercises
Chapter 12: Runtime Configuration
Defining Variables
Command-Line Options and Arguments
Menus
Q&A Dialogue
Configuration Files
Scripts with Several Names
Environment Variables
All Together Now
Script Information
Default Configuration
Screen Variables
Function Definitions
Parse Command-Line Options
Bits and Pieces
Summary
Exercises
Chapter 13: Data Processing
Arrays
Holes in an Indexed Array
Using an Array for Sorting
Two-Dimensional Grids
Data File Formats
Line-Based Records
Block File Formats
Summary
Exercises
Chapter 14: Scripting the Screen
Teletypewriter vs. Canvas
Stretching the Canvas
Command Sequence Introducer
Priming the Canvas
Moving the Cursor
Changing Rendition Modes and Colors
Placing a Block of Text on the Screen
Scrolling Text
Rolling Dice
Summary
Exercises
Chapter 15: Entry-Level Programming
Single-Key Entry
Function Library, key-funcs
History in Scripts
Sanity Checking
Form Entry
Reading the Mouse
Summary
Exercises
Appendix A: Shell Variables
BASH
BASHPID
BASH_ALIASES
BASH_ARGC
BASH_ARGV
BASH_CMDS
BASH_COMMAND
BASH_EXECUTION_STRING
BASH_LINENO
BASH_REMATCH
BASH_SOURCE
BASH_SUBSHELL
BASH_VERSINFO
BASH_VERSION
COMP_CWORD
COMP_KEY
COMP_LINE
COMP_POINT
COMP_TYPE
COMP_WORDBREAKS
COMP_WORDS
DIRSTACK
EUID
FUNCNAME
GROUPS
HISTCMD
HOSTNAME
HOSTTYPE
LINENO
MACHTYPE
OLDPWD
OPTARG
OPTIND
OSTYPE
PIPESTATUS
PPID
PWD
RANDOM
REPLY
SECONDS
SHELLOPTS
SHLVL
UID
BASH_ENV
CDPATH
COLUMNS
COMPREPLY
EMACS
FCEDIT
FIGNORE
GLOBIGNORE
HISTCONTROL
HISTFILE
HISTFILESIZE
HISTIGNORE
HISTSIZE
HISTTIMEFORMAT
HOME
HOSTFILE
IFS
IGNOREEOF
INPUTRC
LANG
LC_ALL
LC_COLLATE
LC_CTYPE
LC_MESSAGES
LC_NUMERIC
LINES
MAIL
MAILCHECK
MAILPATH
OPTERR
PATH
POSIXLY_CORRECT
PROMPT_COMMAND
PROMPT_DIRTRIM
PS1
PS2
PS3
PS4
SHELL
TIMEFORMAT
TMOUT
TMPDIR
auto_resume
histchars
Index
← Prev
Back
Next →
← Prev
Back
Next →