\documentclass{beamer} %include lhs2TeX.fmt \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} \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 38} \date{November 11, 2009} \begin{document} \begin{frame} \maketitle \end{frame} \begin{frame} \frametitle{Summary of last class} \begin{itemize} \item Simple shell program. \begin{spec} $ cmd arg1 arg2 arg3 \end{spec} \pause \item |stdin|/|stdout|/|stderr| redirection \pause \begin{spec} $ cmd arg1 arg2 bar \end{spec} \pause \begin{spec} $ cmd 2>&1 | less # 0-stdin 1-stdout 2-stderr $ cmd >>foo # append to the file foo instead of write \end{spec} \pause \item Pipes \begin{spec} $ cmd1 | cmd2 | cmd3 | cmd \end{spec} \end{itemize} \end{frame} \begin{frame} \frametitle{Shell variables} To assign a shell variable \begin{spec} $ foo=bar # no space between foo and bar \end{spec} \pause To get the value of foo use |$foo| \begin{spec} $ echo the value of variable foo is $foo \end{spec} \pause \begin{block} {Some important shell variables} \begin{itemize} \item |PATH| The directories where an executable is searched \begin{spec} $ export PATH=/bin/:/usr/bin:/usr/local/bin: \end{spec} \item |PS1| The first prompt \item |PS2| the second prompt etc \end{itemize} \end{block} \end{frame} \begin{frame} \frametitle{Funny characters} Shell interpretes some characters differently We have already seen some |<|, |>|, |&|, | || | etc. \pause The character '*' means any sequece of characters \pause \begin{spec} $ ls *.c $ rm *.o \end{spec} \end{frame} \begin{frame} \begin{block}{Protecting characters} \begin{itemize} \item Use |\| to protect funny characters \pause \begin{spec} $ ls filename\ with\ spaces $ echo I am an invisible file > \ \end{spec} \pause \item Quoting with |'| \pause \begin{spec} $ ls 'filename with spaces' $ rm '*' # actually removes a file called * $ echo I am an invisible file > ' ' \end{spec} \pause \item Double quoting |"|. Similar to |'| but shell variables expand \begin{spec} $ foo=bar $ echo '$foo is the value of foo' $ ech "$foo is the value of foo" \end{spec} \end{itemize} \end{block} \end{frame} \begin{frame} \frametitle{The program |grep|} grep is a \emph{filter}. It sends only those lines where a given pattern matches. \pause \begin{spec} grep PATTERN file1 file2 file3 grep PATTERN \end{spec} The pattern can be what is called a regular expression \pause eg. Print all the hidden files (files with name staring with a .) \pause \begin{spec} ls | grep '^\..*' | less # \end{spec} \pause \begin{itemize} \item |^| means start of the line \item |.| means any character \item |r *| means many |r|'s \item I have written the |\.| to \emph{escape} the special meaning \end{itemize} \end{frame} \end{document} \begin{frame} \frametitle{Philosophy of shell programming} There any many small but efficient programs. Combine them. You need to know many of these common programs. \begin{itemize} \item |echo| prints its command line arguments \pause \item |less| shows int |stdin| in pages \begin{spec} $ cmd | less $ less foo bar biz \end{spec} \pause \item |grep pattern| shows only those lines of its stdin that matches the pattern. \end{itemize} \pause There are many more. \pause To learn more, use command prompt always and read manpages. \end{frame}