Chapter 8, Bash

Background

Start-up with bash --login

# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).

if [ "$PS1" ]; then
  if [ "$BASH" ] && [ "$BASH" != "/bin/sh" ]; then
    # The file bash.bashrc already sets the default PS1.
....
# The default umask is now handled by pam_umask.
# See pam_umask(8) and /etc/login.defs.

if [ -d /etc/profile.d ]; then
  for i in /etc/profile.d/*.sh; do

Start-up with bash --login

Start-up with bash --login personalization

When you exit

Start-up of just bash

source, src, or just "dot"

source, src, or just "dot"

Scripting

Short-circuits

Subshells

Job control

The directory stack

Variables

$ var1=xyz
$ declare -r var2=zyx
$ var2=xyz
bash: var2: readonly variable
$ unset var2
bash: unset: var2: cannot unset: readonly variable

Environmental variables

Removing variables

More declarations

   -a   declare an array variable
   -i   declare an integer variable
   -r   read-only variable
   -x   create an environment variable, like export

Important keyword variables

Important keyword variables

Locales

$ locale
LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
[ ... ]
LC_ALL=

Locale

$ locale -c charmap
LC_CTYPE
UTF-8
$

Accessing history with exclamation

Functions

name () {
  [...]
}

shopt

Arithmetic in Bash

$ echo $((3+4))
7
$ echo $((12 == 3))     #  booleans also!
0
$ echo $((12 == 12))
1

Advanced exercises on page 368