All About bash in 30 minutes
Short History
bash descended from ksh and the "bourne shell". The word comes from "Bourne Again SHell".
Currently the default shell on Mac OS X
bash Basics
Case Sensitive
Special Symbols and command lines: #, $, >, <.
bash Quoting: ",', escapes, et cetera
Removing a file called "*"
bash Variables
Process Scope ("Why isn't my symbol assigned?"), running from the "."
Special Variables: $PS1, ${1...}, $$, $HOSTNAME, $USER, $RANDOM
Profile files
.bash_profile
$ENV
Redirection: >,<, >&1 et al
command line history and autocompletion
tab, uparrow..
Programming with bash
When NOT to use bash: when the problem takes more than about 150 lines to solve
Scoping is crude at best
Not object-oriented
Easy to create wonderful, clever, hopelessly confusing code.
Slow
Creating subroutines: foo() { }
Symbol manipulation: ${bif:-} et cetera
Control Flow and Loops: if then else fi, for in do done, while do done, esac
What used to be the test(1) program (aka "[")
Arithmetic processing: "let" and (())
Useful Vocabulary Words (programs): grep(1), awk(1), sed(1), tr(1), seq(1), nl(1), wc(1), find(1) et cetera
Good practices IMNSHOP
Use "set -x" and script(1) for debugging
Make configuration files and write groups of short scripts, rather than one humongo unmaintainable wad of code
Delimiting variables: use full ${} notation to prevent interpreter from making surprising decisions about variable names
Use getopt(1), provide command-line help always
--
CharlesShapiro
- 20 Sep 2007
This topic: ALE
>
WebHome
>
BashCourseOnWheels
Topic revision:
17 December 2009, willyonwheels
Copyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Foswiki?
Send feedback