Bash Quick Reference

Bash Quick Reference

Arnold Robbins

Language: English

Pages: 66

ISBN: 0596527764

Format: PDF / Kindle (mobi) / ePub


In this quick reference, you'll find everything you need to know about the bash shell. Whether you print it out or read it on the screen, this book gives you the answers to the annoying questions that always come up when you're writing shell scripts: What characters do you need to quote? How do you get variable substitution to do exactly what you want? How do you use arrays? It's also helpful for
interactive use.

 

 

 

 

 

 

 

 

 

 

 

 

 

su). wait Wait for background jobs to finish. CTRL-Z Suspend a foreground job. Then use bg or fg. (Your terminal may use something other than CTRL-Z as the suspend character.) Shell Options Bash provides a number of shell options, settings that you can change to modify the shell’s behavior. You control these options with the shopt command (see the shopt entry in the later section “Built-in Commands”). The following descriptions describe the behavior when set. Options marked with a dagger (†) are

substitutions, shell functions, and subshells invoked via (...) inherit the DEBUG and RETURN traps. • Error tracing is enabled. Command substitutions, shell functions, and subshells invoked via (...) inherit the ERR trap. extglob Enable extended pattern-matching facilities such as +(...). (These were not in the Bourne shell and are not in POSIX; thus Bash requires you to enable them if you want them.) extquote † Allow $’...’ and $"..." within ${variable} expansions inside double quotes.

balancing parentheses inside a $( ) construct. See also the nocasematch option in “Shell Options.” Examples Check first command-line argument and take appropriate action: case $1 no|yes) -[tT]) *) esac in # Match the first arg response=1;; table=TRUE;; echo "unknown option"; exit 1;; Read user-supplied lines until user exits: while : # Null command; always true do printf "Type . to finish ==> " read line case "$line" in .) echo "Message done" break ;; *) echo "$line" >> $message ;; esac done

"$1" ] While there are arguments... While there are nonempty arguments... If $count is less than 10... If the RCS directory exists... If the answer is not y... If the first argument is not a readable file or a regular file... Built-in Commands 59 time time command Execute command and print the total elapsed time, user time, and system time (in seconds). Same as the external command time, except that the built-in version can also time other built-in commands as well as all commands in a

${var:pos}, ${var:pos:len} ${var/pat/repl} ${var/pat} ${var//pat/repl} ${var/#pat/repl} ${var/%pat/repl} Set each variable var to a value. Use value of var; braces are optional if var is separated from the following text. They are required for array variables. Use var if set; otherwise, use value. Use var if set; otherwise, use value and assign value to var. Use var if set; otherwise, print value and exit (if not interactive). If value isn’t supplied, print the phrase “parameter null or not

Download sample

Download