Pro Bash Programming: Scripting the GNU/Linux Shell (Expert's Voice in Linux) by Johnson, Chris F. A. (2011) Paperback

Pro Bash Programming: Scripting the GNU/Linux Shell (Expert's Voice in Linux) by Johnson, Chris F. A. (2011) Paperback

Language: English

Pages: 0

ISBN: B00M8P7L16

Format: PDF / Kindle (mobi) / ePub


 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

statement if; and the conditional operators && and ||. Chapter 4, Command-Line Parsing and Expansion, describes how the shell parses a command line, from word splitting to parameter expansion. Chapter 5, Variables and Parameters, covers all the possibilities of parameters and variables, from scalar variables to associative arrays and from default substitution to search and replace. Chapter 6, Shell Functions, delves into the syntax of function definitions and defines a number of useful routines.

Variables........................................................................................................................6 Exercises ...........................................................................................................................6 ■Chapter 2: Input, Output, and Throughput ...............................................................7 Parameter and Variables ...................................................................................................7

${var:-default} and ${var-default}: Use Default Values The most commonly used expansion, ${var:-default}, checks to see whether a variable is unset or empty and expands to a default string if it is: $ var= $ sa "${var:-default}" :default: ## The sa script was introduced in Chapter 4 If the colon is omitted, the expansion checks only whether the variable is unset: $ var= $ sa "${var-default}" ## var is set, so expands to nothing :: $ unset var $ sa "${var-default}" ## var is unset, so expands to

word for each command, either alias, keyword, function, builtin, file, or an empty string: $ type -t echo printf sa time ls builtin builtin function keyword file The type command fails if any of its arguments are not found. builtin, Execute a Builtin Command The argument to builtin is a shell builtin command that will be called rather than a function with the same name. It prevents the function from calling itself and calling itself ad nauseam. cd() #@ DESCRIPTION: change directory and display

The program exits via the die function when a command fails (Listing 12-10c). Listing 12-10c. Define die Function die() #@ Print error message and exit with error code { #@ USAGE: die [errno [message]] error=${1:-1} ## exits with 1 if error number not given shift [ -n "$*" ] && printf "%s%s: %s\n" "$scriptname" ${version:+" ($version)"} "$*" >&2 exit "$error" } 148 CHAPTER 12 „ RUNTIME CONFIGURATION Function: menu The menu function uses its command-line arguments to populate the menu (Listing

Download sample

Download