%% $Header: /cvsroot/lcdp/lpic/general-linux-2/slides/gl2.109.1.slides.tex,v 1.2 2003/08/29 14:36:14 waratah Exp $

\input{gl2.slide-header.tex}

%% Uncomment to turn overlays off for printing.
%\overlaysfalse

%% For overlays
%\newcounter{olayctr}[slide]

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%----10->|-----20->|-----30->|-----40->|-----50->|-----60->|-----70->|-----80->
\begin{slide} %================================================================
\begin{center} \LARGE \textsf{-- General Linux 2 -- \\
Customise and Use the Shell Environment }
\LARGE \textsf{[] } \\[2mm]
\large  \textsf{(Linux Professional Institute Certification)}\\[1mm]

\normalsize\end{center}

\footnote{Copyright \copyright\ 2002 Geoffrey Robertson. 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.}
 
\scriptsize
\begin{verbatim} 
   .~.    
   /V\     by: geoffrey robertson        
  // \\        geoffrey@zip.com.au
  @._.@ 
\end{verbatim} 
\tiny
\begin{verbatim}
$Id: gl2.109.1.slides.tex,v 1.2 2003/08/29 14:36:14 waratah Exp $ 
\end{verbatim} 
\normalsize  
\vfill \end{slide} %-----------------------------------------------------------
%----10->|-----20->|-----30->|-----40->|-----50->|-----60->|-----70->|-----80->

%==============================================================================
\begin{slide} %ghr
  \listofslides
\vfill \end{slide}
%------------------------------------------------------------------------------

%==============================================================================
\begin{slide}{} %ghr
\Slidecontents
\vfill \end{slide} %-----------------------------------------------------------
 
%==============================================================================
%==============================================================================
\begin{slide} %ghr
\slideheading{Shells, Scripting, Programming \& Compiling}
\begin{description}
  \item[2.109.1] {\bf \underline{Customise and use the shell environment []}} 
  \item[2.109.2] Customise or Write Simple Scrips []
\end{description}
\vfill \end{slide} %-----------------------------------------------------------
 
%==============================================================================
\begin{slide}{} %ghr
\Slidecontents
\vfill \end{slide} %-----------------------------------------------------------
 
%==============================================================================
%==============================================================================
\begin{slide} %ghr
\slideheading{Customise and Use the Shell Environment}
\slidesubheading{Objective}
 
Candidate should be able to customise 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.

\vfill \end{slide} %-----------------------------------------------------------
 
%==============================================================================
\begin{slide} %ghr
\Slideheading{Customise and Use the Shell Environment}
\slidesubheading{Key files, terms, and utilities}
\begin{alltt}
~/.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)
\end{alltt}
\vfill \end{slide} %-----------------------------------------------------------
 
%==============================================================================
%==============================================================================
\begin{slide}{}
\slideheading{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[\texttt{\~{}/.bash\_profile}] Executed after
    \texttt{/etc/profile} at login
\reveal
  \item[\texttt{\~{}/.bashrc}] Executed after \texttt{~/.bash\_profile}
    at login
  \end{description}
\reveal
\item Note \texttt{~/.bashrc} is executed when any new \texttt{bash}
  shell is spawned
\end{itemize}
\vfill \end{slide} %-----------------------------------------------------------

%==============================================================================
%==============================================================================
\begin{slide}{}
\slideheading{Bash Aliases}
\begin{itemize}
\overlay{1}
\item
\end{itemize}
\vfill \end{slide} %-----------------------------------------------------------

%==============================================================================
%==============================================================================
\begin{slide}{}
\slideheading{Bash Functions}
\begin{itemize}

\reveal
\item Functions work similarly to aliases but allow more complex constructions.

\reveal
\item They have the following syntax:
\begin{alltt}
\cmd{[ function ] NAME() \{ COMMAND_LIST;\}}
\end{alltt}

\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}

\reveal
\item Functions may be stored in \texttt{\~{}/.bashrc}
\end{itemize}
\vfill \end{slide} %-----------------------------------------------------------

%==============================================================================
\begin{slide}{}
\Slideheading{Bash Functions}
\slidesubheading{Function Example}
\begin{itemize}

\reveal
\item This simple function prints the current working directory and
  the list of files in it:
\begin{alltt}
\cmd{function look() \{ pwd; ls;\}}    
\end{alltt}

\reveal
\item This function would be used like this:
\begin{alltt}
\cmd{look}
/home/geoffrey/lpic/general-linux-2/notes
CVS    _whizzy_gl2.notes.fmt 
_whizzy_gl2.notes.pag
    
\end{alltt}
\end{itemize}
\vfill \end{slide} %-----------------------------------------------------------

%==============================================================================
\begin{slide}{}
\Slideheading{Bash Functions}
\slidesubheading{Valid Function Definitions}
\begin{itemize}
\overlay{1}
\item \verb+$ function look() { pwd; ls;}+
\overlay{2}
\item \verb+$ function look { pwd; ls; }+ 
\overlay{3}
\item \verb+$ look() { pwd; ls;} +
\overlay{4}
\item 
\begin{verbatim}
$ look() 
> {
> pwd;
> ls;
> } 
\end{verbatim}

\end{itemize}
\vfill \end{slide} %-----------------------------------------------------------

%==============================================================================
\begin{slide}{}
\Slideheading{Bash Functions}
\slidesubheading{Invalid Function Definitions}
\begin{itemize}
\overlay{1}
\item \verb+$ function look()  pwd; ls; + 
\overlay{2}
\item \verb+$ look() { pwd; ls } +
\overlay{3}
\item \verb+$ function look() {pwd; ls;}+%$ 
\end{itemize}
\vfill \end{slide} %-----------------------------------------------------------

%==============================================================================
\begin{slide}{}
\Slideheading{Bash Functions}
\slidesubheading{Example from Jeffrey Dean's Nutshell Book}
\begin{itemize}

\overlay{1}
\item A function that uses a command line argument:
\begin{alltt}
\cmd{laps () \{}
> ls -l \$1
> ps aux | grep `/usr/bin/basename \$1`
> \}    
\end{alltt}

\overlay{2}
\item Use the \texttt{laps()} function:
{\scriptsize
\begin{alltt}
\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{alltt}
}
\end{itemize}
\vfill \end{slide} %-----------------------------------------------------------



%==============================================================================
\begin{slide}{} %ghr
\heading{The End}
 \Slidecontents
\vfill \end{slide} %-----------------------------------------------------------


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{document} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%==============================================================================
%==============================================================================
\begin{slide}{}
\slideheading{}


\vfill \end{slide} %-----------------------------------------------------------

=============================================================================
\begin{slide}{}

\end{slide} %------------------------------------------------------------------


%==============================================================================
\begin{slide}{} %ghr
\Slidecontents
\vfill \end{slide} %-----------------------------------------------------------

