\input{gl2.slide-header-beamer}%
\errorcontextlines=99
%% Subtopic Number = '1.109.1'
%% Title from filename: 'Customize and use the shell environment'
%% Weight: 5
%% Description:
%% Candidate should be able to customize shell environments to
%%        meet users' needs. This objective includes setting environment variables
%%        (e.g. PATH) at login or when spawning a new shell. It also includes
%%        writing bash functions for frequently used sequences of commands.
%% Key files, terms, and utilities include:
%%        ~/.bash_profile
%%        ~/.bash_login
%%        ~/.profile
%%        ~/.bashrc
%%        ~/.bash_logout
%%        ~/.inputrc
%%        function (Bash built-in command)
%%        export
%%        env
%%        set (Bash built-in command)
%%        unset (Bash built-in command)
\title{1.109.1\\Customize and use the shell environment\\Weight 5}
\author[Geoff Robertson]{Geoffrey Robertson \texttt{ge@ffrey.com} \and Nick Urbanik \texttt{nicku@nicku.org}\\
  {\tiny This document Licensed under GPL---see
    section~\ref{sec:license}}}%
\subtitle{Linux Professional Institute Certification --- 102}%
\mode<article>{\chead{1.109.1}}%


\begin{document}
\maketitle
\mode<article>{\thispagestyle{empty}}

\begin{frame}
  \frametitle{Outline}
  \mode<presentation>
  {%
    %\footnotesize
    \begin{multicols}{2}
      \tableofcontents
    \end{multicols}
    % You might wish to add the option [pausesections]
  }%
  \mode<article>
  {%
    \tableofcontents
  }%
\end{frame}

\subsection{Context}
\label{sec:context}


\begin{frame}[fragile]
  \frametitle{Topic 109 Shells, Scripting, Programming and Compiling [8]}
  \begin{description}
  \item[1.109.1] \textbf{\uline{Customise and use the shell environment
        [5]}}
  \item[1.109.2] Customise or Write Simple Scripts [3]
  \end{description}
\end{frame}
%-----------------------------------------------------------
 
\section{Objective}
\label{sec:objective}


\begin{frame}
  %% GENERATED SLIDE
  \frametitle{Description of Objective}%
  \framesubtitle{1.109.1\ \ Customize and use the shell environment}%
  \mode<presentation>{\Large}%
  Candidate should be able to customize shell environments to meet
  users' needs. This objective includes setting environment variables
  (e.g. \texttt{PATH}) at login or when spawning a new shell. It also
  includes writing \texttt{bash} functions for frequently used
  sequences of commands.
\end{frame}

\begin{frame}
  %% GENERATED SLIDE
  \frametitle{Key files, terms, and utilities include:}
  \mode<presentation>{\large}%
  \begin{description}
  \item[\texttt{$\sim$/.bash\_profile}] --- sourced when a person
    logs in
  \item[\texttt{$\sim$/.bash\_login}] --- sourced when a person
    logs in if no \texttt{$\sim$/.bash\_profile}
  \item[\texttt{$\sim$/.profile}] --- \sloppypar{}sourced when a person logs
    in if no \texttt{$\sim$/.bash\_profile} or
    \texttt{$\sim$/.bash\_login}
  \item[\texttt{$\sim$/.bashrc}] --- sourced when a non-login
    interactive shell starts
  \item[\texttt{$\sim$/.bash\_logout}] --- sourced when a person logs out
  \item[\texttt{$\sim$/.inputrc}] --- allows a user to specify
    keystrokes for commands
  \item[\texttt{function}] ---  (Bash built-in command)
  \item[\texttt{export}] --- make environment variables available to
    sub processes
  \item[\texttt{env}] --- display environment
  \item[\texttt{set}] ---  (Bash built-in command)
  \item[\texttt{unset}] ---  (Bash built-in command) --- remove any
    definition of an environment variable
  \end{description}
\end{frame}


\section{Bash Configuration Files}
\label{sec:configuration-files}


\begin{frame}[<+->]
\frametitle{Bash Configuration Files}
\begin{itemize}
%\reveal
\item When a user logs in to a \texttt{bash} shell the following
  configuration files are usually executed:
  \begin{description}
%\reveal
  \item[\texttt{/etc/profile}] System wide profile, common to all
    users and shells
%\reveal
  \item[$\sim$\texttt{/.bash\_profile}] sourced after
    \texttt{/etc/profile} at login
%\reveal
  \item[$\sim$\texttt{/.bashrc}] sourced after \texttt{$\sim$/.bash\_profile}
    at login
  \end{description}
%\reveal
\item Note \texttt{$\sim$/.bashrc} is executed when any new \texttt{bash}
  shell is spawned
\end{itemize}
\end{frame}

\section{Aliases}
\label{sec:aliases}


%==============================================================================
\begin{frame}[fragile]
\frametitle{Bash Aliases}
% \begin{itemize}
% \pause
% %\overlay{1}
% \item
% \end{itemize}
\end{frame}

\section{Bash functions}
\label{sec:functions}

\begin{frame}
  \frametitle{Bash Functions}%
  \begin{itemize}
    \pause
    % \reveal
  \item Functions work similarly to aliases but allow more complex
    constructions.%
    \pause%
    % \reveal
  \item They have the following syntax:
    \par%
    \cmdbox{[ function ] NAME() \{ COMMAND\_LIST;\}}
    \par%
    \pause%
    % \reveal
  \item Where
    \begin{description}
    \item[\texttt{function}] Optional tag
    \item[\texttt{NAME()}] The name of the function
    \item[\texttt{COMMAND\_{}LIST}] The body of the function 
    \end{description}
    \pause
    % \reveal
  \item Functions may be stored in $\sim$\texttt{/.bashrc}
  \end{itemize}
\end{frame}

\begin{frame}[fragile]
  \frametitle{Bash Functions}%
  \framesubtitle{Function Example}%
  \begin{itemize}
    % \reveal
    \pause
  \item This simple function prints the current working directory and
    the list of files in it:
    \par%
    \cmdbox{function look() \{ pwd; ls;\}}    
    % \reveal
    \pause
  \item This function would be used like this:
\begin{semiverbatim}
\cmd{look}
/home/geoffrey/lpic/general-linux-2/notes
CVS    _whizzy_gl2.notes.fmt 
_whizzy_gl2.notes.pag
\end{semiverbatim}
  \end{itemize}
\end{frame}

\begin{frame}[fragile]
  \frametitle{Bash Functions}%
  \framesubtitle{Valid Function Definitions}%
  \begin{itemize}
    \pause
    % \overlay{1}
  \item \verb+$ function look() { pwd; ls;}+
    \pause
    % \overlay{2}
  \item \verb+$ function look { pwd; ls; }+ 
    \pause
    % \overlay{3}
  \item \verb+$ look() { pwd; ls;} +
    \pause
    % \overlay{4}
  \item 
\begin{verbatim}
$ look() 
> {
> pwd;
> ls;
> } 
\end{verbatim}
  \end{itemize}
\end{frame}

\begin{frame}[fragile]
  \frametitle{Bash Functions}%
  \framesubtitle{Invalid Function Definitions}%
  \begin{itemize}
    \pause
    % \overlay{1}
  \item \verb+$ function look()  pwd; ls; + 
    \pause
    % \overlay{2}
  \item \verb+$ look() { pwd; ls } +
    \pause
    % \overlay{3}
  \item \verb+$ function look() {pwd; ls;}+%$ 
  \end{itemize}
\end{frame}
%-----------------------------------------------------------

%==============================================================================
\begin{frame}[fragile]
  \frametitle{Bash Functions}
  \framesubtitle{Example from Jeffrey Dean's Nutshell Book}
  \begin{itemize}
    \pause
    % \overlay{1}
  \item A function that uses a command line argument:
\begin{semiverbatim}
\cmd{laps () \{}
> ls -l \$1
> ps aux | grep `/usr/bin/basename \$1`
> \}    
\end{semiverbatim}
    \pause
    % \overlay{2}
  \item Use the \texttt{laps()} function:
  \end{itemize}
{\mode<presentation>{\scriptsize}
\mode<article>{\footnotesize}
\begin{semiverbatim}
\cmd{laps /usr/sbin/sshd} 
-rwxr-xr-x    1 root     root       276200 Jun 29 01:28 /usr/sbin/sshd
root       255  0.0  0.3  2792 1216 ?        S    Aug31   0:00 /usr/sbin/sshd
geoffrey  1187  0.0  0.1  1332  424 pts/1    R    14:39   0:00 grep sshd    
\end{semiverbatim}
}
\end{frame}

\section{License Of This Document}
\label{sec:license}%

\begin{frame}
  \frametitle{License Of This Document}%
  \raggedright%
  Copyright \copyright\ 2005, 2003 Geoffrey Robertson <ge@ffrey.com> and
  Nick Urbanik <nicku@nicku.org>.
  \par
  Permission is granted to make and distribute
  verbatim copies or modified versions of this document provided that
  this copyright notice and this permission notice are preserved on
  all copies under the terms of the GNU General Public License as
  published by the Free Software Foundation---either version 2 of the
  License or (at your option) any later version.
\end{frame}
\end{document}
