From d305a9b065ad24fdae0da47a6d8a7140cd8e0a43 Mon Sep 17 00:00:00 2001 From: Puneeth Chaganti Date: Fri, 10 Jun 2011 15:19:03 +0530 Subject: ult: Fix bug in slides. s/marks.txt/marks1.txt at some instances. --- ult/ult.tex | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'ult') diff --git a/ult/ult.tex b/ult/ult.tex index 62117eb..e1feb3d 100644 --- a/ult/ult.tex +++ b/ult/ult.tex @@ -679,7 +679,7 @@ \begin{frame}[fragile] \frametitle{Redirection and Piping} \begin{lstlisting} - $ cut -d " " -f 2- marks.txt \ + $ cut -d " " -f 2- marks1.txt \ > /tmp/m_tmp.txt $ paste -d " " students.txt m_tmp.txt \end{lstlisting} % $ @@ -687,7 +687,7 @@ or \begin{lstlisting} - $ cut -d " " -f 2- marks.txt \ + $ cut -d " " -f 2- marks1.txt \ | paste -d " " students.txt - \end{lstlisting} % $ @@ -745,10 +745,10 @@ \item Error message is redirected, in the second case \end{itemize} \begin{lstlisting} - $ cut -d " " -c 2- marks.txt \ + $ cut -d " " -c 2- marks1.txt \ > /tmp/m_tmp.txt - $ cut -d " " -f 2- marks.txt 1> \ + $ cut -d " " -f 2- marks1.txt 1> \ /tmp/m_tmp.txt 2> /tmp/m_err.txt \end{lstlisting} % $ \begin{itemize} @@ -763,7 +763,7 @@ \begin{frame}[fragile] \frametitle{Piping} \begin{lstlisting} - $ cut -d " " -f 2- marks.txt \ + $ cut -d " " -f 2- marks1.txt \ | paste -d " " students.txt - \end{lstlisting} % $ \begin{itemize} @@ -852,7 +852,7 @@ \item Command below prints student marks, sorted by name \end{itemize} \begin{lstlisting} - $ cut -d " " -f 2- marks.txt \ + $ cut -d " " -f 2- marks1.txt \ | paste -d " " students.txt - \ | sort \end{lstlisting} % $ @@ -868,7 +868,7 @@ \item The command below sorts based on marks in first subject \end{itemize} \begin{lstlisting} - $ cut -d " " -f 2- marks.txt \ + $ cut -d " " -f 2- marks1.txt \ | paste -d " " students.txt -\ | sort -t " " -k 2 -rn \end{lstlisting} % $ @@ -887,7 +887,7 @@ \item Command below searches \& shows the marks of Anne alone \end{itemize} \begin{lstlisting} - $ cut -d " " -f 2- marks.txt \ + $ cut -d " " -f 2- marks1.txt \ | paste -d " " students.txt - | grep Anne \end{lstlisting} % $ @@ -902,7 +902,7 @@ \item \texttt{-i} for case-insensitive searches \end{itemize} \begin{lstlisting} - $ cut -d " " -f 2- marks.txt \ + $ cut -d " " -f 2- marks1.txt \ | paste -d " " students.txt - | grep -i Anne \end{lstlisting} % $ @@ -911,7 +911,7 @@ \item To see everyone's marks except Anne's \end{itemize} \begin{lstlisting} - $ cut -d " " -f 2- marks.txt \ + $ cut -d " " -f 2- marks1.txt \ | paste -d " " students.txt - | grep -iv Anne \end{lstlisting} % $ @@ -989,7 +989,7 @@ \begin{lstlisting} #!/bin/bash mkdir ~/marks - cut -d " " -f 2- marks.txt \ + cut -d " " -f 2- marks1.txt \ | paste -d " " students.txt - \ | sort > ~/marks/results.txt \end{lstlisting} % $ @@ -1020,7 +1020,7 @@ \begin{lstlisting} #!/bin/bash mkdir ~/marks - cut -d " " -f 2- marks.txt \ + cut -d " " -f 2- marks1.txt \ | paste -d " " students.txt - \ | sort > ~/marks/results.txt echo "Results generated." @@ -1036,7 +1036,7 @@ \begin{lstlisting} #!/bin/bash mkdir ~/marks - cut -d " " -f 2- marks.txt \ + cut -d " " -f 2- marks1.txt \ | paste -d " " students.txt - \ | sort > ~/marks/$1 echo "Results generated." -- cgit From 58630bcb4334866b399da831c72e32c6674cd996 Mon Sep 17 00:00:00 2001 From: Puneeth Chaganti Date: Fri, 10 Jun 2011 16:28:14 +0530 Subject: ult: Add example for iterating over range of numbers. --- ult/handout.rst | 9 +++++++++ ult/ult.tex | 6 ++++++ 2 files changed, 15 insertions(+) (limited to 'ult') diff --git a/ult/handout.rst b/ult/handout.rst index b72dbdc..a1ea9fb 100644 --- a/ult/handout.rst +++ b/ult/handout.rst @@ -1910,6 +1910,15 @@ dummy or a loop variable. It can then be used to refer to the element of the list that is currently being dealt with. We could, obviously, use something as lame as ``i`` in place of ``animal``. +To generate a range of numbers and iterate over them, we do the following. + +:: + + for i in {5..10} + do + echo $i + done + Now, we use a ``for`` loop to list the files that we are interested in. :: diff --git a/ult/ult.tex b/ult/ult.tex index e1feb3d..613409f 100644 --- a/ult/ult.tex +++ b/ult/ult.tex @@ -1211,6 +1211,12 @@ \item Loop over the list; \texttt{animal} is a dummy variable \item Echo value of \texttt{animal} --- each name in list \end{itemize} + \begin{lstlisting} + for i in {10..20} + do + echo $i + done + \end{lstlisting} % $ \end{frame} \begin{frame}[fragile] -- cgit From 638d6b456a95c64a71d0584a89404af1a1c2e8dd Mon Sep 17 00:00:00 2001 From: Puneeth Chaganti Date: Fri, 10 Jun 2011 16:28:35 +0530 Subject: ult: Add content on shell variables and comments. --- ult/handout.rst | 35 +++++++++++++++++++++++++++++++++++ ult/ult.tex | 15 +++++++++++++++ 2 files changed, 50 insertions(+) (limited to 'ult') diff --git a/ult/handout.rst b/ult/handout.rst index a1ea9fb..5ef762a 100644 --- a/ult/handout.rst +++ b/ult/handout.rst @@ -1785,6 +1785,41 @@ So, these are all the paths that are searched, when looking to execute a command. If we put the results.sh script in one of these locations, we could simply run it, without using the ``./`` at the beginning. +Variables +--------- + +As expected, it is possible to define our own variables inside our shell +scripts. For example, + +:: + + name="FOSSEE" + +creates a new variable ``name`` whose value is ``FOSSEE``. To refer to this +variable, inside our shell script, we would refer to it, as ``$name``. +**NOTE** that there is no space around the ``=`` sign. + +:: + + ls $name* + +It is possible to store the output of a command in a variable, by enclosing +the command in back-quotes. + +:: + + count=`wc -l wonderland.txt` + +saves the number of lines in the file ``wonderland.txt`` in the variable +count. + +Comments +-------- + +The ``#`` character is used to comment out content from a shell script. +Anything that appears after the ``#`` character in a line, is ignored by +the bash shell. + Control structures and Operators ================================ diff --git a/ult/ult.tex b/ult/ult.tex index 613409f..a94dc14 100644 --- a/ult/ult.tex +++ b/ult/ult.tex @@ -1012,6 +1012,21 @@ \end{itemize} \end{frame} +\begin{frame}[fragile] + \frametitle{Variables \& Comments} + \begin{lstlisting} + $ name=FOSSEE + $ count=`wc -l wonderland.txt` + $ echo $count # Shows the value of count + \end{lstlisting} % $ + \begin{itemize} + \item It is possible to create variables in shell scripts + \item Variables can be assigned with the output of commands + \item \alert{NOTE:} There is no space around the \texttt{=} sign + \item All text following the \texttt{\#} is considered a comment + \end{itemize} +\end{frame} + \begin{frame}[fragile] \frametitle{\texttt{echo}} \begin{itemize} -- cgit From 0bb8028c7edaf21c4f057af5b49758635f9c5fee Mon Sep 17 00:00:00 2001 From: Puneeth Chaganti Date: Fri, 10 Jun 2011 16:29:04 +0530 Subject: ult: Add exercise to read man of expr command. --- ult/exercises.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'ult') diff --git a/ult/exercises.rst b/ult/exercises.rst index 6f0f052..e8aede3 100644 --- a/ult/exercises.rst +++ b/ult/exercises.rst @@ -73,7 +73,9 @@ Session-2 0. Read through the section ``REGULAR EXPRESSIONS`` in ``man grep`` -1. grep the marks of the students who scored above 75 in atleast one +#. Read through in ``man expr`` + +#. grep the marks of the students who scored above 75 in atleast one subject. #. grep the marks of all the students whose names begin with an 's' -- cgit From 14c806bf85ac4cf2557fb7c850b15272fb768899 Mon Sep 17 00:00:00 2001 From: Puneeth Chaganti Date: Fri, 10 Jun 2011 16:31:23 +0530 Subject: ult: Fix exercise question. --- ult/exercises.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ult') diff --git a/ult/exercises.rst b/ult/exercises.rst index e8aede3..04df5ce 100644 --- a/ult/exercises.rst +++ b/ult/exercises.rst @@ -57,7 +57,7 @@ Session-1 #. Change ownership of the file ``test`` to some other user (if exists). -#. Count the number of files in a directory. +#. Count the number of files (files, sub-directories, etc.) in a directory. #. Create a new file ``alice.txt`` by concatenating the first 30 lines and the last 40 lines of ``wonderland.txt``. -- cgit