\documentclass{beamer}
%
%
\makeatletter
\@ifundefined{lhs2tex.lhs2tex.sty.read}%
  {\@namedef{lhs2tex.lhs2tex.sty.read}{}%
   \newcommand\SkipToFmtEnd{}%
   \newcommand\EndFmtInput{}%
   \long\def\SkipToFmtEnd#1\EndFmtInput{}%
  }\SkipToFmtEnd

\newcommand\ReadOnlyOnce[1]{\@ifundefined{#1}{\@namedef{#1}{}}\SkipToFmtEnd}
\usepackage{amstext}
\usepackage{amssymb}
\usepackage{stmaryrd}
\DeclareFontFamily{OT1}{cmtex}{}
\DeclareFontShape{OT1}{cmtex}{m}{n}
  {<5><6><7><8>cmtex8
   <9>cmtex9
   <10><10.95><12><14.4><17.28><20.74><24.88>cmtex10}{}
\DeclareFontShape{OT1}{cmtex}{m}{it}
  {<-> ssub * cmtt/m/it}{}
\newcommand{\texfamily}{\fontfamily{cmtex}\selectfont}
\DeclareFontShape{OT1}{cmtt}{bx}{n}
  {<5><6><7><8>cmtt8
   <9>cmbtt9
   <10><10.95><12><14.4><17.28><20.74><24.88>cmbtt10}{}
\DeclareFontShape{OT1}{cmtex}{bx}{n}
  {<-> ssub * cmtt/bx/n}{}
\newcommand{\tex}[1]{\text{\texfamily#1}}	% NEU

\newcommand{\Sp}{\hskip.33334em\relax}
\newcommand{\NB}{\textbf{NB}}
\newcommand{\Todo}[1]{$\langle$\textbf{To do:}~#1$\rangle$}

\EndFmtInput
\makeatother
%
\author{Piyush P Kurur\\
  Office no: 224\\
  Dept. of Comp. Sci. and Engg.\\
  IIT Kanpur}


\newcommand{\Token}[2][]{\node(#2#1)[token]{#2};}
\newcommand{\Symbol}[2][]{\node(#2#1)[symbol]{#2};}
\newcommand{\Point}[1]{\node(#1)[point]{#1};}

\usepackage{tikz}
\usetikzlibrary{positioning,shapes,chains,fit,shadows}
\usetikzlibrary{shapes.symbols}
\usetikzlibrary{matrix}
\usetikzlibrary{backgrounds}
\usetikzlibrary{shapes.geometric}
\usepackage{multicol}

\usepackage{algorithm2e}
\usepackage{pgfkeys}


%% \newcommand{\SingleLinkedList}[1]{
%%   \foreach \datum/\anchor in {#1}
%%   \begin{scope}
%%     \node[rectangle, fill=yellow!30]{#2};
%%     \node[rectangle, below, fill=green!30](#1){$\cdot$};
%%   \end{scope}
%% }
%% \newcommand{\Null}{
%%   \node[circle, fill=black, minimum size=1em]{};
%% }
\pgfkeys {%
  /tikz/oval/.style={%
    shape=ellipse,
    inner sep=1pt,
    drop shadow,
    draw = black
  },
  /tikz/redbox/.style={%
    shape=rectangle,%
    minimum size=1.5em,%
    top color = white, %
    bottom color=red!50!black!50,
    inner sep=0pt,
    draw=black
  },
  /tikz/null/.style={%
    shape=circle,
    minimum size=0.5em,
    draw=black,
  },
  /tikz/greybox/.style={ 
    shape=rectangle,%
    minimum width=7em,%
    minimum height=1.5em,
    fill=black!20,
    inner sep=0pt,
    draw=black
  },
  /tikz/blackbox/.style={ 
    shape=rectangle,%
    minimum width=7em,%
    minimum height=1.5em,
    fill=black,
    inner sep=0pt,
    draw=black
   },
  /tikz/whitebox/.style={
    shape=rectangle,
    minimum width=7em,
    minimum height=1.5em,
    draw=black
  },
  /tikz/bluebox/.style={
    shape=rectangle,
    minimum width=7em,
    minimum height=1.5em,
    fill=blue!40,
    draw=black
  },
  /tikz/whitetape/.style={
    shape=rectangle,
    minimum width=4em,
    minimum height=1.5em,
    draw=black
  },
  /tikz/bluearr/.style={
    ->,
    line width=0.25em, 
    draw=blue!40
  },
  /tikz/greenarr/.style={
    ->,
    line width=0.25em, 
    draw=green!40!black!60
  }
}
    
\newcommand{\arraythree}[4]{
  \begin{tikzpicture}[node distance=0]
    \pgfsetstrokeopacity{#4};
    \node[#1](a0#3){#2};
    \node[#1, right=of a0#3](a1#3){#2};
    \node[#1, right=of a1#3](a1#3){#2};
  \end{tikzpicture}
}

\newcommand{\arraytwo}[4]{
  \begin{tikzpicture}[node distance=0]
    \pgfsetstrokeopacity{#4};
    \node[#1](a0#3){#2};
    \node[#1,right=of a0#3]{#2};
  \end{tikzpicture}
}
  
\newcommand{\Array}[0]{
  \arraythree{box}{}{a}{1}
}

\newcommand{\AArray}[0]{%
  \arraythree{bbox}{\Array}{b}{0.5}}
\newcommand{\AAArray}[0]{%
  \arraytwo{bbbox}{\AArray}{c}{0.25}}

    
    
\newcommand{\T}[1]{\ensuremath{T\left(#1\right)}}  
\newcommand{\BigOh}[1]{\ensuremath{O\left(#1\right)}}
\title{Fundamentals of Computing: Lecture 37}
\date{November 9, 2009}
\begin{document}
\begin{frame}
  \maketitle
\end{frame}

\begin{frame}
  \frametitle{The Unix system}
  \begin{tikzpicture}
    \node[oval,fill=yellow!30]{
      \begin{tikzpicture}[node distance=0pt]
        \node(shell){shell};
        \node[oval, fill=yellow!40, below=of shell]{
          \begin{tikzpicture}
            \node(user){user programs};
            \node[oval, fill=red!30, below=of user]{
              \begin{tikzpicture}
                \node(kernel){kernel};
                \node[oval, fill= red!40, below=of kernel]{hardware};
              \end{tikzpicture}
            };
          \end{tikzpicture}
        };
      \end{tikzpicture}
    };
  \end{tikzpicture}


\end{frame}
\begin{frame}
  \frametitle{The Shell}
  \begin{itemize}
    \pause
  \item The command processor
    \pause
  \item In non-graphical mode is the first that is executed on login.
    \pause
  \item Is programmable.
    \pause
  \item Collection of shell commands forms a shell program.
  \end{itemize}
  
  \pause
  \begin{block}{Which shell?}
    \pause 

    There are many shells available, each slightly different syntax.

    We will use the \text{\tt bash} shell. Other common shells are \text{\tt csh}, \text{\tt zsh} etc.
  \end{block}

\end{frame}

\begin{frame}
  \frametitle{Simplest shell program}
  The starting \text{\tt \char36{}} is the prompt. You dont have to type it.
  \begin{tabbing}\tt
~~~~\char36{}~programname~arg1~arg2~arg2
\end{tabbing}
  e.g.
  \begin{tabbing}\tt
~~~~\char36{}~echo~foo~bar~biz
\end{tabbing}

\end{frame}

\begin{frame}
  \frametitle{Redirecting a file to input and output to file}
  Remember that every program has three open files,
  \text{\tt stdin}, \text{\tt stdout}, \text{\tt stderr}
  \begin{itemize}
  \item If we write \text{\tt \char36{}~cmd~\char60{}foo} then the \text{\tt stdin} of \text{\tt cmd} is
    the file \text{\tt foo} and not the keyboard.
  \item If we write \text{\tt \char36{}~cmd~\char62{}foo} then the \text{\tt stdout} of \text{\tt cmd} is
    the file \text{\tt foo} and not the monitor.
  \end{itemize}
  
  \begin{tabbing}\tt
~\char36{}~cat~\char62{}~foo\\
\tt ~I~am~redirecting~the~output~of~cat~to~foo\char46{}\\
\tt ~\char36{}~cat~\char60{}~foo\\
\tt ~I~am~redirecting~the~output~of~cat~to~foo\char46{}\\
\tt ~\char36{}~exit
\end{tabbing}
\end{frame}
\begin{frame}
\frametitle{One can also redirect \text{\tt stderr}}

\begin{itemize}
  \pause
\item Redirecting \text{\tt stderr} to a file   \text{\tt cmd~2\char62{}foo} (no space between \text{\tt 2} and \text{\tt \char62{}})
  \pause
\item Redirecting \text{\tt stderr} to \text{\tt stdout} \text{\tt cmd~2\char62{}\char38{}1}(no space between \text{\tt \char38{}} and \text{\tt 1})
\end{itemize}

\pause
\begin{tabbing}\tt
~~~\char36{}~gcc~badCFile\char46{}c~\\
\tt ~~~\char35{}~Too~much~data~~see~in~pages\\
\tt ~~~\char36{}~gcc~badCFile~2\char62{}\char38{}1~\char124{}~less
\end{tabbing}

\pause

This also tells us about piping.

\begin{tabbing}\tt
~~~\char36{}~cmd1~\char124{}~cmd2~\char124{}~cmd3~\char124{}~cmd4\\
\tt ~~~\char36{}
\end{tabbing}

\end{frame}

\begin{frame}
  \frametitle{Some useful programs}
  \begin{itemize}
  \item \text{\tt echo} prints its command line arguments
  \item \text{\tt less} shows int \text{\tt stdin} in pages
  \item \text{\tt grep~pattern} shows only those lines of its stdin 
    that matches the pattern.
  \end{itemize}
\end{frame}

\end{document}

