diff options
-rw-r--r-- | ult/ult_10/script.rst | 392 | ||||
-rw-r--r-- | ult/ult_10/ult10.tex | 265 | ||||
-rw-r--r-- | ult/ult_5/script.rst | 20 | ||||
-rw-r--r-- | ult/ult_5/ult5.tex | 8 | ||||
-rw-r--r-- | ult/ult_6/script.rst | 50 | ||||
-rw-r--r-- | ult/ult_6/ult_6.tex | 32 | ||||
-rw-r--r-- | ult/ult_7/script.rst | 69 | ||||
-rw-r--r-- | ult/ult_7/script2col.rst | 210 | ||||
-rw-r--r-- | ult/ult_8/marks1.txt | 5 | ||||
-rwxr-xr-x | ult/ult_8/results.sh | 3 | ||||
-rw-r--r-- | ult/ult_8/script.rst | 348 | ||||
-rw-r--r-- | ult/ult_8/students.txt | 5 | ||||
-rw-r--r-- | ult/ult_8/ult8.tex | 256 | ||||
-rw-r--r-- | ult/ult_9/06- track.mp3 | 0 | ||||
-rw-r--r-- | ult/ult_9/clause.sh | 20 | ||||
-rw-r--r-- | ult/ult_9/dir-test.sh | 5 | ||||
-rw-r--r-- | ult/ult_9/emerald.mp3 | 0 | ||||
-rw-r--r-- | ult/ult_9/for-1.sh | 4 | ||||
-rw-r--r-- | ult/ult_9/for-2.sh | 4 | ||||
-rw-r--r-- | ult/ult_9/for-3.sh | 4 | ||||
-rw-r--r-- | ult/ult_9/for-5.sh | 4 | ||||
-rw-r--r-- | ult/ult_9/premier.mp3 | 0 | ||||
-rw-r--r-- | ult/ult_9/script.rst | 441 | ||||
-rw-r--r-- | ult/ult_9/sign.sh | 7 | ||||
-rw-r--r-- | ult/ult_9/society.mp3 | 0 | ||||
-rw-r--r-- | ult/ult_9/ult9.tex | 221 | ||||
-rw-r--r-- | ult/ult_9/while-1.sh | 4 | ||||
-rw-r--r-- | ult/ult_9/while-2.sh | 7 |
28 files changed, 2097 insertions, 287 deletions
diff --git a/ult/ult_10/script.rst b/ult/ult_10/script.rst new file mode 100644 index 0000000..28aa50e --- /dev/null +++ b/ult/ult_10/script.rst @@ -0,0 +1,392 @@ +.. Objectives +.. ---------- + + .. At the end of this tutorial, you will be able to: + + .. 1. Search for files in many different ways + .. 2. Compare files with same names + .. 3. Create and extract an archive + .. 4. Customize a shell + +.. Prerequisites +.. ------------- + +.. 1. Getting started with Linux +.. 2. Basic File Handling + + +Script +------ + +.. L1 + +{{{ Show the first slide containing title, name of the production +team along with the logo of MHRD }}} + +.. R1 + +Hello friends and Welcome to the tutorial on +'Miscellaneous Tools'. + +.. L2 + +{{{ Show slide with objectives }}} + +.. R2 + +At the end of this tutorial, you will be able to, + + 1. Search for files in many different ways. + #. Compare files with same names. + #. Create and extract an archive. + #. Customize a shell. + +.. L3 + +{{{ Switch to the pre-requisite slide }}} + +.. R3 + +Before beginning this tutorial,we would suggest you to complete the +previous tutorials as being displayed currently. + +.. R4 + +There are a bunch of tools, that will prove to be handy in your day +to day work. These tools will help you quickly perform tasks like searching +for files, comparing files and checking if they are the same, viewing the +exact differences between them, etc. + +.. L4 + +.. L5 + +{{{ Show slide, find }}} + +.. R5 + +Let us start with the first tool - 'find' . +The ``find`` command lets you find files in a directory hierarchy. It +offers a very complex feature set allowing you to search for files with a +wide range of restrictions. We shall only look at some of the most +frequently used ones. + +.. R6 + +To find the files, which end with an extension, ``.pdf``, saved in the current +folder and all it's subfolders, we say + +.. L6 + +{{{ Open the terminal }}} +:: + + find . -name "*.pdf" + +.. R7 + +The ``find`` command also lists out the directory and sub-directory names +To list them, we say, + +.. L7 +:: + + find . -type d + +.. R8 + +In short, ``find`` allows you to set limits on file-size, modification time +and whole lot of other things which you can explore on seeing the man page +of ``find``. + +.. L8 + +.. R9 + +Let us now move on to the next tool, the compare tool. + +To compare two files, whether they are identical or not, we can use the +``cmp`` command. Let us consider some situation. Suppose, we run the ``find`` +command to locate some file, and it turns out that we have a file with same +name in different location. + +In this case, if we are unsure, whether both the files are the same, we can use +the ``cmp`` command to check if the files are identical. + +.. L9 +:: + + find . -name quick.c + ./Desktop/programs/quick.c + ./c-folder/quick.c + cmp Desktop/programs/quick.c c-folder/quick.c + +.. L10 + +{{{ Show slide, cmp }}} + +.. R10 + +If the cmp command doesn't return any output, it means that both files are +exactly identical. If there are any differences in the file, it gives you +the exact byte location at which the first difference occurred. + +.. R11 + +Let us now make a small change in one of quick.c file and run the ``cmp`` +command again. + +.. L11 + +{{{ Switch to the terminal }}} + +:: + + cmp Desktop/programs/quick.c c-folder/quick.c + +.. R12 + +As we can see, it gives the exact location as to where a change is made. + +Now, we may not be happy with just the knowledge that the files are +different. We may want to see the exact differences between the two files. +The ``diff`` command can be used to find the exact differences between the +files. + +.. L12 + +.. L13 +:: + + diff Desktop/programs/quick.c c-folder/quick.c + +.. R13 + +We get back a line by line difference between the two files. + +.. L14 + +{{{ Show slide, diff }}} + +.. R14 + +The ``>`` mark indicates the content that has been added to the second file, +which was not present in the first file. The ``<`` mark indicates the lines +that were present in the first file, but are not existent in the second file. + +.. L15 + +{{{ Show slide, tar }}} + +.. R15 + +You would often come across (archive) files which are called *tarballs*. A +tar ball is essentially a collection of files, which may or may not be +compressed. Essentially, it eases the job of storing, backing up and +transporting multiple files, at once. + +.. R16 + +The following set of commands extracts the contents of the ``allfiles.tar`` +tarball to the directory extract. + +.. L16 + +{{{ Switch to terminal }}} +:: + + mkdir extract + cp allfiles.tar extract/ + cd extract + tar -xvf allfiles.tar + +.. L17 + +{{{ Show slide, extracting an archive }}} + +.. R17 + +The option, ``x`` tells ``tar`` to extract the files in the archive file +specified by the ``f`` option. The ``v`` option tells ``tar`` to give out a +verbose output. + +.. R18 + +Similarly, if we wish to create a ``tar`` archive, we use the ``c`` option +instead of the ``x`` option. For instance, the command below creates an +archive from all the files with the ``.txt`` extension. + +.. L18 + +{{{ Switch to terminal }}} +:: + + tar -cvzf newarchive.tar *.txt + +.. R19 + +You can also create and extract compressed archives using ``tar``. It +supports a wide variety of compressions like gzip, bzip2, lzma, etc. + +We need to add an additional option to ``tar`` to handle these +compressions. + + ++-------------+------------+ +| Compression | Option | ++-------------+------------+ +| gzip | ``-z`` | +| bzip2 | ``-j`` | +| lzma | ``--lzma`` | ++-------------+------------+ + +.. L19 + +.. R20 + +So, if we wished to create a gzip archive in the previous command, we +change it to the following + +.. L20 +:: + + tar -cvzf newarchive.tar.gz *.txt + +.. L21 + +{{{ Show slide, customizing your shell }}} + +.. R21 + +What would you do, if you want bash to execute a particular command each +time you start it up? For instance, say you want the current directory to +be your Desktop instead of your home folder, each time bash starts up. +Bash reads and executes commands in a whole bunch +of files called start-up files, when it starts up. + +When bash starts up as an interactive login shell, it reads the files +``/etc/profile``, ``~/.bash_profile``, ``~/.bash_login``, and +``~/.profile`` in that order. + +When an interactive shell that is not a login shell is started, bash reads +and executes commands from ~/.bashrc. This can be prevented using the ``--norc`` +option. Instead of using the ``~/.bashrc`` file on start-up, we can force +the bash to use another file, for which the ``--rcfile`` option may be used. + +Now, you know what you should do, to change the current directory to you +Desktop. Just put a ``cd ~/Desktop`` into your ``~/.bashrc`` and you are +set! +But as you know that the start-up files are used for a lot more complex things +than this. You could set (or unset) aliases and a whole bunch of environment +variables in the ``.bashrc``, like changing environment variables etc. + +.. L22 + +{{{ Switch to 'Summary' slide }}} + +.. R22 + +This brings us to the end of the end of this tutorial. +In this tutorial, we have learnt to, + + 1. Make use of the ``find`` command to find files in a directory hierarchy. + #. Find the differences between files with the same name, using the + ``cmp`` and ``diff`` commands. + +.. L23 + +{{{ Switch to 'Summary..' slide }}} + +.. R23 + + #. Extract and create compressed archive's using the ``tar`` command. + #. Customize one's shell according to one's choice. + +.. L24 + +{{{ Show self assessment questions slide }}} + +.. R24 + +Here are some self assessment questions for you to solve + + 1. Look at the man page of ``find`` and state the options which + deal with symbolic links. + + 2. How do you append tar files to an archive? + +.. L25 + +{{{ Solution of self assessment questions on slide }}} + +.. R25 + +And the answers, + +1. The -H, -L and -P options with the ``find`` command control + the treatment of symbolic links. + + 2. To append tar files to an archive, we can use the ``tar`` command + either with the ``-A`` option or the ``-r`` option, as, +:: + + $ tar -Af <tar_file> <tar_file_to_be_added> + OR + $ tar -rf <tar_file> <tar_file_to_be_added> + +.. L27 + +{{{ Show the SDES & FOSSEE slide }}} + +.. R27 + +Software Development techniques for Engineers and Scientists - SDES, is an +initiative by FOSSEE. For more information, please visit the given link. + +Free and Open-source Software for Science and Engineering Education - FOSSEE, is +based at IIT Bombay which is funded by MHRD as part of National Mission on +Education through ICT. + +.. L28 + +{{{ Show the ``About the Spoken Tutorial Project'' slide }}} + +.. R28 + +Watch the video available at the following link. It summarises the Spoken +Tutorial project.If you do not have good bandwidth, you can download and +watch it. + +.. L29 + +{{{ Show the `` Spoken Tutorial Workshops'' slide }}} + +.. R29 + +The Spoken Tutorial Project Team conducts workshops using spoken tutorials, +gives certificates to those who pass an online test. + +For more details, contact contact@spoken-tutorial.org + +.. L30 + +{{{ Show the ``Acknowledgements'' slide }}} + +.. R30 + +Spoken Tutorial Project is a part of the "Talk to a Teacher" project. +It is supported by the National Mission on Education through ICT, MHRD, +Government of India. More information on this mission is available at the +given link. + +.. L31 + +{{{ Show the Thank you slide }}} + +.. R31 + +Hope you have enjoyed this tutorial and found it useful. +Thank you! + + + diff --git a/ult/ult_10/ult10.tex b/ult/ult_10/ult10.tex new file mode 100644 index 0000000..9df5525 --- /dev/null +++ b/ult/ult_10/ult10.tex @@ -0,0 +1,265 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Using Linux Tools +% +% Author: FOSSEE +% Copyright (c) 2009, FOSSEE, IIT Bombay +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\documentclass[17pt,compress]{beamer} +\usepackage{beamerthemesplit} +\mode<presentation> +{ + \usetheme{Warsaw} + \useoutertheme{infolines} + \setbeamercovered{transparent} + \setbeamertemplate{navigation symbols}{} +} +% Taken from Fernando's slides. +\usepackage{ae,aecompl} +\usepackage[scaled=.95]{helvet} + +\usepackage[english]{babel} +\usepackage[latin1]{inputenc} +\usepackage[T1]{fontenc} + +% change the alerted colour to LimeGreen +\definecolor{LimeGreen}{RGB}{50,205,50} +\setbeamercolor{structure}{fg=LimeGreen} +\author[FOSSEE]{} +\institute[IIT Bombay]{} +\date[]{} +% \setbeamercovered{transparent} + +% theme split +\usepackage{verbatim} +\newenvironment{colorverbatim}[1][]% +{% +\color{blue} +\verbatim +}% +{% +\endverbatim +}% + +\usepackage{mathpazo,courier,euler} +\usepackage{listings} +\lstset{language=sh, + basicstyle=\ttfamily\bfseries, + showstringspaces=false, + keywordstyle=\color{black}\bfseries} + +% logo +\logo{\includegraphics[height=1.30 cm]{../images/3t-logo.pdf}} +\logo{\includegraphics[height=1.30 cm]{../images/fossee-logo.pdf} + +\hspace{7.5cm} +\includegraphics[scale=0.99]{../images/fossee-logo.pdf}\\ +\hspace{281pt} +\includegraphics[scale=0.80]{../images/3t-logo.pdf}} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% DOCUMENT STARTS +\begin{document} + +\sffamily \bfseries +\title +[Miscellaneous Tools] +{Miscellaneous Tools} +\author +[FOSSEE] +{\small Talk to a Teacher\\{\color{blue}\url{http://spoken-tutorial.org}}\\\vspace{0.25cm}National Mission on Education + through ICT\\{\color{blue}\url{ http://sakshat.ac.in}} \\ [1.9cm] + Contributed by FOSSEE Team \\IIT Bombay \\[0.3cm] +} + +% slide 1 +\begin{frame} + \titlepage +\end{frame} + + +\begin{frame} +\frametitle{Objectives} +\label{sec-2} + +At the end of this tutorial, you will be able to, +\begin{itemize} +\item Search for files in various ways +\item Compare files with same names +\item Create and extract an archive +\item Customize a shell +\end{itemize} +\end{frame} + +\begin{frame} +\frametitle{Pre-requisites} +\label{sec-3} + +Spoken tutorial on, +\begin{itemize} +\item Getting started with Linux +\item Basic File Handling +\end{itemize} +\end{frame} + +\begin{frame}[fragile] + \frametitle{\texttt{`find'}} + \begin{itemize} + \item `find' command helps to find files in a directory hierarchy + \item Offers a very complex feature set\\ For eg: search files by name, owner, date,etc. + \item Look at the \texttt{man} page of `find' + \end{itemize} +\end{frame} + +\begin{frame}[fragile] + \frametitle{\texttt{`cmp'}} + \begin{lstlisting} + $ find . -name quick.c + ./Desktop/programs/quick.c + ./c-folder/quick.c + $ cmp Desktop/programs/quick.c + c-folder/quick.c + \end{lstlisting} % $ + \begin{itemize} + \item No output when files are exactly same + \item Else, gives location where the first difference occurs + \end{itemize} +\end{frame} + +\begin{frame}[fragile] + \frametitle{\texttt{`diff'}} + \begin{itemize} + \item We know the files are different, but want exact differences i.e. line by line + \end{itemize} +\hspace{30pt}\verb~$diff Desktop/programs/quick.c ~\\ +\hspace{40pt}\verb~c-folder/quick.c~ + + \begin{itemize} + \item \texttt{>} indicates content only in second file + \item \texttt{<} indicates content only in first file + \end{itemize} +\end{frame} + +\begin{frame}[fragile] +\frametitle{\texttt{`tar'}} +\begin{itemize} +\item \emph{tarball} -- essentially a collection of files +\item May or may not be compressed +\item Eases the job of storing, backing-up \& transporting files +\end{itemize} +\end{frame} + +\begin{frame}[fragile] +\frametitle{Extracting an archive} +\verb~mkdir extract~ +\verb~cp allfiles.tar extract/~ +\verb~cd extract~\\ +\verb~tar -xvf allfiles.tar~ + + +\begin{itemize} +\item \texttt{-x} --- Extract files within the archive +\item \texttt{-f} --- Specify the archive file +\item \texttt{-v} --- Be verbose +\end{itemize} +\end{frame} + +\begin{frame}[fragile] + \frametitle{Compressed archives} + \begin{itemize} + \item \texttt{tar} - create \& extract compressed archives + \item Additional option to handle compressed archives + \begin{center} + \begin{tabular}{|l|l|}\hline + Compression & Option \\\hline + gzip & \texttt{-z} \\\hline + bzip2 & \texttt{-j} \\\hline + lzma & \texttt{-{}-lzma} \\\hline + \end{tabular} + \end{center} + \end{itemize} +\end{frame} + + +\begin{frame} +\frametitle{Customizing your shell} +\begin{itemize} +\item Bash reads \texttt{/etc/profile}, + \texttt{\textasciitilde{}/.bash\_profile}, + \texttt{\textasciitilde{}/.bash\_login}, and + \texttt{\textasciitilde{}/.profile} in that order, when starting + up as a login shell. +\item \texttt{\textasciitilde{}/.bashrc} is read, when not a login + shell +\end{itemize} +\end{frame} + + +\begin{frame} +\frametitle{Summary} +\label{sec-8} + + In this tutorial, we have learnt to, + + +\begin{itemize} +\item Use ``find'' command to find files in a directory hierarchy +\item Find differences between files with the same name, using the + ``cmp'' and ``diff'' commands +\end{itemize} +\end{frame} + +\begin{frame} +\frametitle{Summary..} +\label{sec-8} + +\begin{itemize} +\item Extract and create compressed archive's using the ``tar'' command +\item Customize one's shell according to one's choice +\end{itemize} +\end{frame} + +\begin{frame}[fragile] +\frametitle{Evaluation} +\label{sec-9} + + +\begin{enumerate} +\item Look at the man page of ``find'' and state the options which + deal with symbolic links. +\vspace{8pt} +\item How do you append tar files to an archive ? +\end{enumerate} +\end{frame} +\begin{frame} +\frametitle{Solutions} + +\begin{enumerate} +\item -H, -L and -P +\vspace{15pt} +\item \$tar -Af <tar-file><tar-file-to-be-added> +\begin{center} +OR \\ +\end{center} +\$tar -rf <tar-file><tar-file-to-be-added> +\end{enumerate} + +\end{frame} +\begin{frame} + + \begin{block}{} + \begin{center} + {\Large THANK YOU!} + \end{center} + \end{block} +\begin{block}{} + \begin{center} + For more Information, visit our website\\ + {\color{blue}\url{http://fossee.in/}} + \end{center} + \end{block} +\end{frame} + +\end{document} + + + diff --git a/ult/ult_5/script.rst b/ult/ult_5/script.rst index 2937397..6502f5c 100644 --- a/ult/ult_5/script.rst +++ b/ult/ult_5/script.rst @@ -44,14 +44,14 @@ At the end of this tutorial, you will be able to, .. R3 Before beginning this tutorial,we would suggest you to complete the -former tutorials as being displayed currently. +previous tutorials as being displayed currently. .. R4 Let us begin with the concept of 'Redirection and Piping' which performs the same operations as the ``cut`` and ``paste`` commands. -Consider the files ``marks.txt`` and ``students.txt``.The contents of +Consider the files ``marks1.txt`` and ``students.txt``.The contents of the files are as following: .. L4 @@ -175,7 +175,7 @@ Let us complete the solution by using the ``paste`` command. So, in two steps we solved the problem of getting rid of the roll numbers from the marks file and displaying the marks along with the names of the -students. Now, that we know how to redirect output, we could choose to +students. Now that we know how to redirect output, we could choose to write the output to a file, instead of showing on the display. Let us now look at the first solution. @@ -206,8 +206,8 @@ upto the ``|`` character, it appears as a normal ``cut`` command . So, the ``|`` character here, seems to be joining the two commands in some way. -Essentially, what we are doing is, to redirect the output of the first -command to ``stdin`` and the second command takes the input from the ``stdin``. +Essentially, what we are doing is, redirect the output of the first +command to ``stdin`` which then becomes input to the second command. This activity is commonly called piping and the character ``|`` is called a pipe. @@ -219,9 +219,9 @@ a pipe. This is roughly equivalent to using two redirects and a temporary file. - command1 > tempfile - command2 < tempfile - rm tempfile + - command1 > tempfile + - command2 < tempfile + - rm tempfile Also, given that a pipe is just a way to send the output of a command to the ``stdin``, it should be obvious to you that we can use a chain of @@ -238,7 +238,7 @@ This brings us to the end of the end of this tutorial. In this tutorial, we have learnt to, 1. Use the ``cut`` and ``paste`` commands in redirection. - 2. Use the pipe ( | ) character. + 2. Apply the concept of Piping. .. L19 @@ -248,7 +248,7 @@ In this tutorial, we have learnt to, Here are some self assessment questions for you to solve: -1. How will you redirect the content of a file to a device ? +1. How to redirect content from file to device ? 2. How to view last field(30), in a file located at /home/test.txt whose first line is "data:myscripts:20:30" diff --git a/ult/ult_5/ult5.tex b/ult/ult_5/ult5.tex index 7f22fc6..16b813e 100644 --- a/ult/ult_5/ult5.tex +++ b/ult/ult_5/ult5.tex @@ -95,7 +95,7 @@ Spoken tutorial on, \begin{itemize} \item Getting started with Linux \item Basic File Handling -\item Advanced file handling +\item Advanced File handling \end{itemize} \end{frame} @@ -182,7 +182,7 @@ $ cut -d " " -f 2- marks1.txt \begin{itemize} \item Use the ``cut'' and ``paste'' commands in redirection -\item Use the pipe ( | ) character +\item Apply the concept of Piping \end{itemize} \end{frame} \begin{frame}[fragile] @@ -191,9 +191,9 @@ $ cut -d " " -f 2- marks1.txt \begin{enumerate} -\item How will you redirect the content of a file to a device ? +\item How to redirect content from file to device ? \vspace{12pt} -\item How to view last field(30), in a file located at \verb~/home/test.txt~ +\item How to view last field (30), in a file located at \verb~/home/test.txt~ whose first line is "data:myscripts:20:30" \vspace{5pt} \begin{itemize} diff --git a/ult/ult_6/script.rst b/ult/ult_6/script.rst index 020f3a6..0cb3c7b 100644 --- a/ult/ult_6/script.rst +++ b/ult/ult_6/script.rst @@ -11,7 +11,7 @@ .. 1. Getting started with Linux .. 2. Basic File Handling -.. 4. Advanced file handling + Script ------ @@ -24,7 +24,7 @@ team along with the logo of MHRD }}} .. R1 Hello friends and Welcome to the tutorial on -'Redirection and Piping'. +'Features of the Shell'. .. L2 @@ -44,7 +44,7 @@ At the end of this tutorial, you will be able to, .. R3 Before beginning this tutorial,we would suggest you to complete the -former tutorials as being displayed currently. +previous tutorials as being displayed currently. .. L4 @@ -73,12 +73,12 @@ latter one, hitting the tab key a second time, will list the possibilities. Bash provides tab completion for the following. - File Names - Directory Names - Executable Names - User Names (when they are prefixed with a ~) - Host Names (when they are prefixed with a @) - Variable Names (when they are prefixed with a $) +- File Names +- Directory Names +- Executable Names +- User Names (when they are prefixed with a ~)- tilde +- Host Names (when they are prefixed with a @)- at sign +- Variable Names (when they are prefixed with a $)- dollar sign .. R6 @@ -127,7 +127,7 @@ command directives. The shell meta characters are recognized anywhere they appear in the command line, even if they are not surrounded by blank space. For that reason, it is safest to only use the characters A-Z, a-z, 0-9, and the period, dash, and underscore characters when naming files and directories - on Unix. If your file or directory has a shell meta character in the name, +on Unix. If your file or directory has a shell meta character in the name, you will find it difficult to use the name in a shell command. The characters that you see on the slide are the shell meta characters @@ -147,8 +147,8 @@ Let's take an example, .. R11 -It means, run on a directory containing the files file, file.c, file.lst, and -myfile would list the files file.c and file.lst. However, +It means, run on a directory containing the files - file.c, file.lst, and +file.txt. However, .. L11 @@ -158,28 +158,27 @@ myfile would list the files file.c and file.lst. However, .. R12 -Run on the same directory would only list file.c because the ? only -matches one character, no more, no less. This can save you a great deal of -typing time. +Run on the same directory would only list file.c because the ?(question mark) +matches only one character, in our case it is ``.c``. This can save you a great +deal of typing time. -For example, if there is a file called california_cornish_hens_with_wild_rice -and no other files whose names begin with 'c', you could view the file without -typing the whole name by typing this +.. L13 -.. L12 +{{{ Show slide, with File names }}} +.. R13 + +For example,if there is a file called ``california_cornish_hens_with_wild_rice`` +and no other files whose names begin with 'c', you could view the file without +typing the whole name by typing :: more c* -.. R13 - Here, the c* matches that long file name. -File-names containing metacharacters can pose many problems and should never -be intentionally created. - -.. L13 +Hence, File-names containing metacharacters can pose many problems and should +never be intentionally created. .. L14 @@ -277,3 +276,4 @@ given link. Hope you have enjoyed this tutorial and found it useful. Thank you! + diff --git a/ult/ult_6/ult_6.tex b/ult/ult_6/ult_6.tex index c42fa21..23108d9 100644 --- a/ult/ult_6/ult_6.tex +++ b/ult/ult_6/ult_6.tex @@ -82,8 +82,8 @@ At the end of this tutorial, you will be able to, \begin{itemize} -\item Understand various features of the shell -\item Learn about shell meta characters +\item Understand various features of the Shell +\item Learn about Shell Metacharacters \end{itemize} \end{frame} @@ -109,12 +109,12 @@ Spoken tutorial on, \begin{frame}[fragile] \frametitle{Tab-completion..} \begin{itemize} - \item Bash provides tab completion for the following + \item Bash provides tab completion for, \begin{enumerate} \item File Names \item Directory Names \item Executable Names - \item User Names (when prefixed with a \~{}) + \item User Names (when prefixed with a \~{} ) \item Host Names (when prefixed with a @) \item Variable Names (when prefixed with a \$) \end{enumerate} @@ -125,23 +125,37 @@ Spoken tutorial on, \frametitle{History} \begin{itemize} \item Bash saves history of commands typed -\item Up and down arrow keys allow to navigate history +\item Up and down arrow keys allow to navigate through history \item \texttt{Ctrl-r} searches for commands used \item No. of commands limited, generally upto 1000 \end{itemize} \end{frame} \begin{frame}[fragile] - \frametitle{Shell Meta Characters} + \frametitle{Shell Metacharacters} \begin{itemize} - \item ``meta characters'' are special command directives - \item No meta-characters in file-names + \item ``Metacharacters'' are special command directives + \item No Metacharacters in file-names \item While naming files, use characters A-Z, a-z, 0-9, . , - , \_ - \item shell meta characters -- \\ + \item shell Metacharacters -- \\ \verb+/<>!$%^&*|{}[]"'`~;+ \end{itemize} \end{frame} +\begin{frame}[fragile] + \frametitle{File names} + \begin{itemize} +\item Eg: Consider a file named \verb+california_cornish_hens_with_+ +\verb+wild_rice+ +\item If no other file-name begins with ``c'', +\end{itemize} +\hspace{29pt}\verb~$ more c*~ +\begin{itemize} +\item c* matches that long file name +\end{itemize} +\end{frame} + + \begin{frame} \frametitle{Summary} \label{sec-8} diff --git a/ult/ult_7/script.rst b/ult/ult_7/script.rst index b4cb55c..eddd9e6 100644 --- a/ult/ult_7/script.rst +++ b/ult/ult_7/script.rst @@ -50,7 +50,7 @@ At the end of this tutorial, you will be able to, .. R3 Before beginning this tutorial,we would suggest you to complete the -former tutorials as being displayed currently. +previous tutorials as being displayed currently. .. R4 @@ -70,7 +70,7 @@ Let us see what data they contain. Open a terminal and type, .. R5 Let's say we wish to sort the output in the alphabetical order -of the names of the files. We can use the ``sort`` command for this +of the names of students. We can use the ``sort`` command for this purpose. We just pipe the previous output to the ``sort`` command as, @@ -259,47 +259,58 @@ original file and work with that file. .. L19 :: - sort items.txt | uniq + sort items.txt > items-sorted.txt .. R20 -``uniq -u`` command gives the lines which are unique and do not have any -duplicates in the file. ``uniq -d`` outputs only those lines which -have duplicates. +Now, the ``uniq`` command will work. Let's try it out + +.. L20 -.. L20 :: - uniq -u items-sorted.txt + uniq items-sorted.txt .. R21 +The same result can also be obtained by a more precise command. We include the +option ``-u`` which gives the lines which are unique and do not have any +duplicates in the file + +.. L21 +:: + + uniq -u items-sorted.txt + +.. R22 + +``uniq -d`` outputs only those lines which have duplicates. The ``-c`` option displays the number of times each line occurs in the file. -.. L21 +.. L22 :: uniq -dc items-sorted.txt -.. L22 +.. L23 {{{ Show summary slide }}} -.. R22 +.. R23 This brings us to the end of the end of this tutorial. In this tutorial, we have learnt to, - 1. Use the ``sort`` command to sort lines of text files. - #. Use the ``grep`` command to search text pattern. - #. Use the ``tr`` command to translate and/or delete characters. - #. Use the ``uniq`` command to omit repeated lines in a text. +1. Use the ``sort`` command to sort lines of text files. +#. Use the ``grep`` command to search text pattern. +#. Use the ``tr`` command to translate and/or delete characters. +#. Use the ``uniq`` command to omit repeated lines in a text. -.. L23 +.. L24 {{{ Show self assessment questions slide }}} -.. R23 +.. R24 Here are some self assessment questions for you to solve @@ -314,11 +325,11 @@ Here are some self assessment questions for you to solve 3. Sort the output of the ``ls -al`` command. -.. L24 +.. L25 {{{ Solution of self assessment questions on slide }}} -.. R24 +.. R25 And the answers, @@ -338,11 +349,11 @@ And the answers, The -n means "sort numerically", and the -k5 option means to key off of column five. -.. L25 +.. L26 {{{ Show the SDES & FOSSEE slide }}} -.. R25 +.. R26 Software Development techniques for Engineers and Scientists - SDES, is an initiative by FOSSEE. For more information, please visit the given link. @@ -351,43 +362,43 @@ Free and Open-source Software for Science and Engineering Education - FOSSEE, is based at IIT Bombay which is funded by MHRD as part of National Mission on Education through ICT. -.. L26 +.. L27 {{{ Show the ``About the Spoken Tutorial Project'' slide }}} -.. R26 +.. R27 Watch the video available at the following link. It summarises the Spoken Tutorial project.If you do not have good bandwidth, you can download and watch it. -.. L27 +.. L28 {{{ Show the `` Spoken Tutorial Workshops'' slide }}} -.. R27 +.. R28 The Spoken Tutorial Project Team conducts workshops using spoken tutorials, gives certificates to those who pass an online test. For more details, contact contact@spoken-tutorial.org -.. L28 +.. L29 {{{ Show the ``Acknowledgements'' slide }}} -.. R28 +.. R29 Spoken Tutorial Project is a part of the "Talk to a Teacher" project. It is supported by the National Mission on Education through ICT, MHRD, Government of India. More information on this mission is available at the given link. -.. L29 +.. L30 {{{ Show the Thank you slide }}} -.. R29 +.. R30 Hope you have enjoyed this tutorial and found it useful. Thank you! diff --git a/ult/ult_7/script2col.rst b/ult/ult_7/script2col.rst deleted file mode 100644 index b15e85c..0000000 --- a/ult/ult_7/script2col.rst +++ /dev/null @@ -1,210 +0,0 @@ -.. Objectives -.. ---------- - - .. At the end of this tutorial, you will be able to: - - .. 1. Sort lines of text files - .. 2. Print lines matching a pattern - .. 3. Translate or delete characters - .. 4. Omit repeated lines - - -.. Prerequisites -.. ------------- - -.. 1. Getting started with Linux -.. 2. Redirection and Piping - - - -Script ------- - - - -+----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ -| {{{ Show the first slide containing title, name of the production | Hello friends and Welcome to the tutorial on 'Text Processing'. | -| team along with the logo of MHRD }}} | | -+----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ -| {{{ Show slide with objectives }}} | At the end of this tutorial, you will be able to, | -| | | -| | 1. Sort lines of text files | -| | #. Print lines matching a pattern | -| | #. Translate or delete characters | -| | #. Omit repeated lines. | -+----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ -| {{{ Switch to the pre-requisite slide }}} | Before beginning this tutorial,we would suggest you to complete the | -| | former tutorials as being displayed currently. | -+----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ -| {{{ Open the terminal }}} | In this tutorial, we shall learn about text processing. | -| :: | TO begin with, consider data kept in two files, namely marks1.txt and | -| | students.txt | -| cat marks1.txt | Let us see what data they contain. Open a terminal and type, | -| cat students.txt | | -+----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ -| :: | Let's say we wish to sort the output in the alphabetical order | -| | of the names of the files. We can use the ``sort`` command for this | -| cut -d " " -f 2- marks1.txt | paste -d " " students.txt -| sort | purpose. | -| | | -| | We just pipe the previous output to the ``sort`` command as, | -+----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ -| :: | Let's say we wish to sort the names, based on the marks in the first | -| | subject i.e. the first column after the name. ``sort`` command also allows us to | -| cut -d " " -f 2- marks1.txt | paste -d " " students.txt -| sort -t " " -k 2 | specify the delimiter between the fields and sort the data on a particular | -| | field. ``-t`` option is used to specify the delimiter and ``-k`` option | -| | is used to specify the field. | -+----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ -| {{{ Show slide with, Sort... }}} | This command give us a sorted output as required. But, what if we would | -| | like the output to appear in the reverse order. ``-r`` option allows the output | -| | to be sorted in the reverse order and the ``-n`` option is used to choose | -| | a numerical sorting. | -+----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ -| {{{ Switch to the terminal }}} | Let us do it on the terminal and see for ourselves, | -| :: | | -| | | -| cut -d " " -f 2- marks1.txt | paste -d " " students.txt -| | | -| sort -t " " -k 2 -rn | | -+----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ -| :: | Suppose, While you are compiling the student marklist, Anne walks up to you and | -| | wants to know her marks. You, being a kind person that you are, oblige. | -| cut -d " " -f 2- marks1.txt | paste -d " " students.txt - | grep Anne | But you do not wish to her to see the marks that others have scored. What | -| | do you do? Here, the ``grep`` command comes to your rescue. | -| | | -| | ``grep`` is a command line text search utility. You can use it to search | -| | for Anne and show her, what she scored. ``grep`` allows us to search for a | -| | search string in files. But we could, like any other command, pipe the | -| | output of other commands to it. So, we shall use the previous combination | -| | of cut and paste that we had, to get the marks of students along with their | -| | names and search for Anne in that. | -+----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ -| :: | This will give us only the line containing the word Anne as the output. | -| | The grep command is by default case-sensitive. So, we wouldn't have got | -| cut -d " " -f 2- marks1.txt | paste -d " " students.txt - | grep -i Anne | the result if we had searched for anne, with a small a, instead of | -| | Anne, with a capital a. But, what if we didn't know, whether the name was | -| | capitalized or not? ``grep`` allows you to do case-insensitive searches | -| | by using the ``-i`` option. | -+----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ -| :: | Now, in another scenario, if we wished to print all the lines, which do | -| | not contain the word Anne, we could use the ``-v`` option. | -| cut -d " " -f 2- marks1.txt | paste -d " " students.txt - | grep -iv Anne | | -+----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ -| {{{ Switch to the terminal }}} | grep allows us to do more complex searches, for instance, searching for | -| :: | sentences starting or ending with a particular pattern and regular | -| | expression based searches. | -| cat students.txt | tr a-z A-Z | | -| | {{{ Show slide with, tr }}} | -| | | -| | ``tr`` is a command that takes two sets of characters as parameters, and | -| | replaces occurrences of the characters in the first set with the | -| | corresponding elements from the other set. It reads from the standard | -| | output and writes to the standard output. | -| | | -| | For instance, if we wish to replace all the lower case letters in the | -| | students file with upper case, we can do it as, | -+----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ -| :: | A common task is to remove empty newlines from a file. The ``-s`` flag | -| | causes ``tr`` to compress sequences of identical adjacent characters in its | -| tr -s '\n' '\n' | output to a single token. For example, | -+----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ -| :: | Hit enter 2-3 times and see that every time we hit enter we get a newline. | -| | | -| <Enter> | | -| <Enter> | | -+----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ -| :: | It replaces sequences of one or more newline characters with a single newline. | -| | | -| cat foo.txt | tr -d '\r' > bar.txt | The ``-d`` flag causes ``tr`` to delete all tokens of the specified set of | -| | characters from its input. In this case, only a single character set | -| | argument is used. The following command removes carriage return characters, | -| | thereby converting a file in DOS/Windows format to the Unix format. | -+----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ -| :: | The ``-c`` flag complements the first set of characters. | -| | | -| tr -cd '[:alnum:]' | | -+----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ -| :: | It therefore removes all non-alphanumeric characters. | -| | | -| cat items.txt | Let us consider one more scenario.Suppose we have a list of items, say books, | -| | and we wish to obtain a list which names of all the books only once, without | -| | any duplicates. To achieve this, we use the ``uniq`` command. Let us first | -| | have a look at our file | -+----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ -| :: | Now, let us try and get rid of the duplicate lines from this file using | -| | the ``uniq`` command. | -| uniq items.txt | | -+----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ -| :: | Nothing happens! Why? The ``uniq`` command removes duplicate lines only when | -| | they are next to each other. So, henceforth, we get a sorted file from the | -| sort items.txt | uniq | original file and work with that file. | -+----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ -| :: | ``uniq -u`` command gives the lines which are unique and do not have any | -| | duplicates in the file. ``uniq -d`` outputs only those lines which | -| uniq -u items-sorted.txt | have duplicates. | -+----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ -| :: | The ``-c`` option displays the number of times each line occurs in the file. | -| | | -| uniq -dc items-sorted.txt | | -+----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ -| {{{ Show summary slide }}} | This brings us to the end of the end of this tutorial. | -| | In this tutorial, we have learnt to, | -| | | -| | 1. Use the ``sort`` command to sort lines of text files. | -| | #. Use the ``grep`` command to search text pattern. | -| | #. Use the ``tr`` command to translate and/or delete characters. | -| | #. Use the ``uniq`` command to omit repeated lines in a text. | -+----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ -| {{{ Show self assessment questions slide }}} | Here are some self assessment questions for you to solve | -| | | -| | 1. To obtain patterns; one per line, which of the following command is used ? | -| | | -| | - grep -f | -| | - grep -i | -| | - grep -v | -| | - grep -e | -| | | -| | 2. Translate the word 'linux' to upper-case. | -| | | -| | 3. Sort the output of the ``ls -al`` command. | -+----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ -| {{{ Solution of self assessment questions on slide }}} | And the answers, | -| | | -| | 1. In order to obtain patterns one per line, we use the ``grep`` command | -| | alongwith the -f option. | -| | | -| | 2. We use the tr command to change the word into uppercase | -| | :: | -| | | -| | echo 'linux' | tr a-z A-Z | -| | | -| | | -| | 3. We use the sort command as, | -| | :: | -| | | -| | ls -al | sort -n -k5 | -| | The -n means "sort numerically", and the -k5 option means to key off of | -| | column five. | -+----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ -| {{{ Show the SDES & FOSSEE slide }}} | Software Development techniques for Engineers and Scientists - SDES, is an | -| | initiative by FOSSEE. For more information, please visit the given link. | -| | | -| | Free and Open-source Software for Science and Engineering Education - FOSSEE, is | -| | based at IIT Bombay which is funded by MHRD as part of National Mission on | -| | Education through ICT. | -+----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ -| {{{ Show the ``About the Spoken Tutorial Project'' slide }}} | Watch the video available at the following link. It summarises the Spoken | -| | Tutorial project.If you do not have good bandwidth, you can download and | -| | watch it. | -+----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ -| {{{ Show the `` Spoken Tutorial Workshops'' slide }}} | The Spoken Tutorial Project Team conducts workshops using spoken tutorials, | -| | gives certificates to those who pass an online test. | -| | | -| | For more details, contact contact@spoken-tutorial.org | -+----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ -| {{{ Show the ``Acknowledgements'' slide }}} | Spoken Tutorial Project is a part of the "Talk to a Teacher" project. | -| | It is supported by the National Mission on Education through ICT, MHRD, | -| | Government of India. More information on this mission is available at the | -| | given link. | -+----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ -| {{{ Show the Thank you slide }}} | Hope you have enjoyed this tutorial and found it useful. | -| | Thank you! | -+----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ diff --git a/ult/ult_8/marks1.txt b/ult/ult_8/marks1.txt new file mode 100644 index 0000000..9a5299d --- /dev/null +++ b/ult/ult_8/marks1.txt @@ -0,0 +1,5 @@ +5 89 92 85 +4 98 47 67 +1 67 82 76 +2 78 97 60 +3 67 68 69 diff --git a/ult/ult_8/results.sh b/ult/ult_8/results.sh new file mode 100755 index 0000000..acdac84 --- /dev/null +++ b/ult/ult_8/results.sh @@ -0,0 +1,3 @@ +#!/bin/bash +mkdir ~/marks +cut -d " " -f 2- marks1.txt | paste -d " " students.txt - | sort > ~/marks/results.txt diff --git a/ult/ult_8/script.rst b/ult/ult_8/script.rst new file mode 100644 index 0000000..1e3f425 --- /dev/null +++ b/ult/ult_8/script.rst @@ -0,0 +1,348 @@ +.. Objectives +.. ---------- + + .. At the end of this tutorial, you will be able to: + + .. 1. Prepare a simple shell script. + .. 2. Run a script successfully and print it's result. + .. 3. Understand what an environment variable is. + +.. Prerequisites +.. ------------- + +.. 1. Getting started with Linux +.. 2. Basic file handling +.. 3. Redirection and Piping +.. 4. Text Processing + + + +Script +------ + +.. L1 + +{{{ Show the first slide containing title, name of the production +team along with the logo of MHRD }}} + +.. R1 + +Hello friends and Welcome to the tutorial on +'Shell scripts & Variables'. + +.. L2 + +{{{ Show slide with objectives }}} + +.. R2 + +At the end of this tutorial, you will be able to, + + 1. Prepare a simple shell script. + #. Run a script successfully and print it's result. + #. Understand what an environment variable is. + +.. L3 + +{{{ Switch to the pre-requisite slide }}} + +.. R3 + +Before beginning this tutorial,we would suggest you to complete the +previous tutorials as being displayed currently. + +.. R4 + +Let us start with creating a simple shell script. +A shell script is simply a sequence of commands, that are put into a file, +instead of entering them one by one onto the shell. The script can then be +run, to run the sequence of commands in a single shot instead of manually +running, each of the individual commands. +For instance, let's say we wish to create a directory called ``marks`` in the +home folder and save the results of the students into a file +``results.txt``. + +.. L4 + +.. R5 + +We open an editor and save the following text to ``results.sh`` + +.. L5 + +{{{ Open an editor and type the following }}} +:: + + #!/bin/bash + mkdir ~/marks + cut -d " " -f 2- marks1.txt | paste -d " " students.txt - | sort > ~/marks/ + results.txt + +.. R6 + +We can now run the script as, + +.. L6 + +{{{ Open the terminal }}} +:: + + ./results.sh + +.. R7 + +We get an error saying, Permission denied! Why? Can you think of the +reason? Yes, the file doesn't have execute permissions. +We make the file executable and then run it. + +.. L7 +:: + + chmod u+x results.sh + ./results.sh + +.. R8 + +We get back the prompt. We can check the contents of the file +``results.txt`` to see if the script has run. + +So, here, we have our first shell script. The first line of the script is used +to specify the interpreter or shell which should be used to execute the script. +In this case, we are asking it to use the bash shell. +Once, the script has run, we get back the prompt. Here, we had to manually +check, if the contents of the file are correct. It would be useful to have our +script print out messages. For this, we can use the ``echo`` command. We can +edit ``results.sh`` script, as follows. + +.. L8 + +{{{ Open an editor and type the following }}} +:: + + #!/bin/bash + mkdir ~/marks + cut -d " " -f 2- marks1.txt | paste -d " " students.txt - | sort > ~/marks/ + results.txt + echo "Results generated." + +.. R9 + +Now, on running the script, we get a message on the screen informing us, +when the script has run. + +Let's now say, that we wish to let the user decide the file to which the +results should be written to. The results file, should be specifiable by an +argument in the command line. We can do so, by editing the file, as below. + +.. L9 + +{{{ Make the necessary changes in the previous script }}} + +:: + + #!/bin/bash + mkdir ~/marks + cut -d " " -f 2- marks1.txt|paste -d " " students.txt - | sort > ~/marks/$1 + echo "Results generated." + + +{{{ Highlight the text ``$1`` }}} + +.. R10 + +The ``$1`` above, corresponds to the first command line argument to the +script. So, we can run the script as shown below, to save the results to +``grades.txt``. + +.. L10 +:: + + ./results.sh grades.txt + +.. R11 + +When we run the ``results.sh`` file, we are specifying the location of the +script by using ``./``. But for any of the other commands, +we didn't have to specify their locations. Why? The +shell has a set of locations where it searches, for the command that we are +trying to run. + +.. L11 + +.. L12 + +{{{ Show slide, PATH }}} + +.. R12 + +These set of locations are saved in an "environment" +variable called PATH.let us look at what the value of the PATH variable is. +To view the values of variables, we can use the echo command. + +.. L13 + +{{{ Switch to the terminal }}} +:: + + echo $PATH + +.. R13 + +So, these are all the paths that are searched, when looking to execute a +command. If we put ``results.sh`` script in one of these locations, we +could simply run it, without using the ``./`` at the beginning. + +.. R14 + +As expected, it is possible to define our own variables inside our shell +scripts. For example, + +.. L14 + +{{{ Switch to the terminal }}} +:: + + name="FOSSEE" + +.. R15 + +It 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. + +.. L15 +:: + + ls $name* + + +.. R16 + +It is possible to store the output of a command in a variable, by enclosing +the command in back-quotes. + +.. L16 +:: + + count=`wc -l wonderland.txt` + +.. R17 + +It saves the number of lines in the file ``wonderland.txt`` in the variable +count. + +.. L17 + +.. L18 + +{{{ Show slide, variables & comments }}} + +.. R18 + +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. + +.. L19 + +{{{ Switch to 'Summary' slide }}} + +.. R19 + +This brings us to the end of the end of this tutorial. +In this tutorial, we have learnt to, + +1. Prepare a shell script. +#. Display the result of a script, using the ``echo`` command. +#. Use the environment variable ``PATH``. +#. Create variables and comment out content using the ``#`` sign. + +.. L20 + +{{{ Show self assessment questions slide }}} + +.. R20 + +Here are some self assessment questions for you to solve + +1. Which sign is used to comment out content from a shell script. + + - $ + - % + - # + - * + +2. How will you add directory ``/data/myscripts`` to the beginning of + the $PATH environment variable ? + +.. L21 + +{{{ Solution of self assessment questions on slide }}} + +.. R21 + +And the answers, + +1. We use the ``#`` sign to comment out the content from a shell script. + +2. In order to add a directory to the beginning of the $PATH variable,we + say, +:: + + $PATH=/data/myscripts:$PATH + +.. L22 + +{{{ Show the SDES & FOSSEE slide }}} + +.. R22 + +Software Development techniques for Engineers and Scientists - SDES, is an +initiative by FOSSEE. For more information, please visit the given link. + +Free and Open-source Software for Science and Engineering Education - FOSSEE, is +based at IIT Bombay which is funded by MHRD as part of National Mission on +Education through ICT. + +.. L23 + +{{{ Show the ``About the Spoken Tutorial Project'' slide }}} + +.. R23 + +Watch the video available at the following link. It summarises the Spoken +Tutorial project.If you do not have good bandwidth, you can download and +watch it. + +.. L24 + +{{{ Show the `` Spoken Tutorial Workshops'' slide }}} + +.. R24 + +The Spoken Tutorial Project Team conducts workshops using spoken tutorials, +gives certificates to those who pass an online test. + +For more details, contact contact@spoken-tutorial.org + +.. L35 + +{{{ Show the ``Acknowledgements'' slide }}} + +.. R35 + +Spoken Tutorial Project is a part of the "Talk to a Teacher" project. +It is supported by the National Mission on Education through ICT, MHRD, +Government of India. More information on this mission is available at the +given link. + +.. L26 + +{{{ Show the Thank you slide }}} + +.. R26 + +Hope you have enjoyed this tutorial and found it useful. +Thank you! + + diff --git a/ult/ult_8/students.txt b/ult/ult_8/students.txt new file mode 100644 index 0000000..ddacd6b --- /dev/null +++ b/ult/ult_8/students.txt @@ -0,0 +1,5 @@ +Hussain +Dilbert +Anne +Raul +Sven diff --git a/ult/ult_8/ult8.tex b/ult/ult_8/ult8.tex new file mode 100644 index 0000000..a315ba1 --- /dev/null +++ b/ult/ult_8/ult8.tex @@ -0,0 +1,256 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Using Linux Tools +% +% Author: FOSSEE +% Copyright (c) 2009, FOSSEE, IIT Bombay +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\documentclass[17pt,compress]{beamer} +\usepackage{beamerthemesplit} +\mode<presentation> +{ + \usetheme{Warsaw} + \useoutertheme{infolines} + \setbeamercovered{transparent} + \setbeamertemplate{navigation symbols}{} +} +% Taken from Fernando's slides. +\usepackage{ae,aecompl} +\usepackage[scaled=.95]{helvet} + +\usepackage[english]{babel} +\usepackage[latin1]{inputenc} +\usepackage[T1]{fontenc} + +% change the alerted colour to LimeGreen +\definecolor{LimeGreen}{RGB}{50,205,50} +\setbeamercolor{structure}{fg=LimeGreen} +\author[FOSSEE]{} +\institute[IIT Bombay]{} +\date[]{} +% \setbeamercovered{transparent} + +% theme split +\usepackage{verbatim} +\newenvironment{colorverbatim}[1][]% +{% +\color{blue} +\verbatim +}% +{% +\endverbatim +}% + +\usepackage{mathpazo,courier,euler} +\usepackage{listings} +\lstset{language=sh, + basicstyle=\ttfamily\bfseries, + showstringspaces=false, + keywordstyle=\color{black}\bfseries} + +% logo +\logo{\includegraphics[height=1.30 cm]{../images/3t-logo.pdf}} +\logo{\includegraphics[height=1.30 cm]{../images/fossee-logo.pdf} + +\hspace{7.5cm} +\includegraphics[scale=0.99]{../images/fossee-logo.pdf}\\ +\hspace{281pt} +\includegraphics[scale=0.80]{../images/3t-logo.pdf}} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% DOCUMENT STARTS +\begin{document} + +\sffamily \bfseries +\title +[Shell scripts \& Variables] +{Shell scripts \& Variables} +\author +[FOSSEE] +{\small Talk to a Teacher\\{\color{blue}\url{http://spoken-tutorial.org}}\\\vspace{0.25cm}National Mission on Education + through ICT\\{\color{blue}\url{ http://sakshat.ac.in}} \\ [1.65cm] + Contributed by FOSSEE Team \\IIT Bombay \\[0.3cm] +} + +% slide 1 +\begin{frame} + \titlepage +\end{frame} + +\begin{frame} +\frametitle{Objectives} +\label{sec-2} + +At the end of this tutorial, you will be able to, +\begin{itemize} +\item Prepare a simple shell script. +\item Run a script successfully and print it's result. +\item Understand what an environment variable is. +\end{itemize} +\end{frame} + +\begin{frame} +\frametitle{Pre-requisites} +\label{sec-3} + +Spoken tutorial on, +\begin{itemize} +\item Getting started with Linux +\item Basic file handling +\item Redirection and Piping +\item Text Processing +\end{itemize} +\end{frame} + +\begin{frame}[fragile] + \frametitle{\texttt{PATH}} + \begin{itemize} + \item Shell searches in a set of locations + \item Locations are saved in ``environment'' variable called PATH + \end{itemize} + \hspace{30pt}\texttt{\$ echo \$PATH} + %\hspace{26pt} \verb~$ echo $PATH~ + \begin{itemize} + \item Put results.sh in 1 of these locations + \item It can then be run without \texttt{./} + \end{itemize} +\end{frame} + +\begin{frame}[fragile] + \frametitle{Variables \& Comments} + \verb~$ name=FOSSEE~ + \verb~$ count=`wc -l wonderland.txt`~ + \verb~$ echo $count # Shows the value~ + \verb~of count~ + \begin{itemize} + \item \alert{NOTE:} No space around the \texttt{=} sign + \item All text following the \texttt{\#} is considered a comment + \end{itemize} +\end{frame} + +\begin{frame} +\frametitle{Summary} +\label{sec-8} + + In this tutorial, we have learnt to, + + +\begin{itemize} +\item Prepare a shell script. +\item Display the result of a script, using the ``echo'' command. +\item Use the environment variable ``PATH''. +\item Create variables and comment out content using the ``\#'' sign. +\end{itemize} +\end{frame} + +\begin{frame}[fragile] +\frametitle{Evaluation} +\label{sec-9} + + +\begin{enumerate} +\item Which sign is used to comment out content from a shell script?\\ +%\begin{itemize} +{\color{LimeGreen}$\bullet$} \$ \hspace{80pt}{\color{LimeGreen}$\bullet$} \% \\ +{\color{LimeGreen}$\bullet$} \# \hspace{80pt}{\color{LimeGreen}$\bullet$} * \\ +\vspace{8pt} +\item How will you add directory ``/data/scripts'' to the beginning of + the \$PATH environment variable ? +\end{enumerate} +\end{frame} + +%\begin{frame}[fragile] +%\frametitle{Evaluation} +%\label{sec-9} + + +%\begin{enumerate} +%\item Which sign is used to comment out content from a shell script? +%\begin{itemize} +%\item \$ +%\item \% +%\item \# +%\item * +%\end{itemize} +%\vspace{8pt} +%\item How will you add directory ``/data/myscripts'' to the beginning of +% the \$PATH environment variable ? +%\end{enumerate} +%\end{frame} + +\begin{frame} +\frametitle{Solutions} +\label{sec-10} + + +\begin{enumerate} +\item `` \# '' +\vspace{15pt} +\item \texttt{\$ PATH=/data/scripts:\$PATH} +\end{enumerate} +\end{frame} + +\begin{frame} +\frametitle{SDES \& FOSSEE} +\begin{center} +\begin{itemize} +\item \small{SDES}\\ +\small{\color{LimeGreen}Software Development techniques for Engineers and Scientists} \\ +\scriptsize An initiative by FOSSEE. \\ +\vspace{3pt} +\scriptsize For more information on SDES, please visit {\color{blue}\url{http://fossee.in/sdes}}\\ +\vspace{10pt} +\item \small{FOSSEE}\\ +\small {\color{LimeGreen}Free and Open-source Software for \\Science and Engineering Education} \\ +\scriptsize Based at IIT Bombay, Funded by MHRD.\\ +\vspace{3pt} +\scriptsize Part of National Mission on Education through ICT \\(NME-ICT) \\ +\end{itemize} +\end{center} +\end{frame} + +\begin{frame} +\frametitle{About the Spoken Tutorial Project} +\begin{itemize} +\item Watch the video available at {\color{blue}\url{http://spoken-tutorial.org /What\_is\_a\_Spoken\_Tutorial}} +\item It summarises the Spoken Tutorial project +\item If you do not have good bandwidth, you can download and watch it +\end{itemize} +\end{frame} + +\begin{frame} +\frametitle{Spoken Tutorial Workshops}The Spoken Tutorial Project Team +\begin{itemize} +\item Conducts workshops using spoken tutorials +\item Gives certificates to those who pass an online test +\item For more details, please write to \\ \hspace {0.5cm}{\color{blue}contact@spoken-tutorial.org} +\end{itemize} +\end{frame} + +\begin{frame} +\frametitle{Acknowledgements} +\begin{itemize} +\item Spoken Tutorial Project is a part of the Talk to a Teacher project +\item It is supported by the National Mission on Education through ICT, MHRD, Government of India +\item More information on this Mission is available at: \\{\color{blue}\url{http://spoken-tutorial.org/NMEICT-Intro}} +\end{itemize} +\end{frame} + +\begin{frame} + + \begin{block}{} + \begin{center} + {\Large THANK YOU!} + \end{center} + \end{block} +\begin{block}{} + \begin{center} + For more Information, visit our website\\ + {\color{blue}\url{http://fossee.in/}} + \end{center} + \end{block} +\end{frame} + + +\end{document} + + diff --git a/ult/ult_9/06- track.mp3 b/ult/ult_9/06- track.mp3 new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/ult/ult_9/06- track.mp3 diff --git a/ult/ult_9/clause.sh b/ult/ult_9/clause.sh new file mode 100644 index 0000000..23017f2 --- /dev/null +++ b/ult/ult_9/clause.sh @@ -0,0 +1,20 @@ +#!/bin/sh +# Script to greet the user according to time of day +hour=`date | cut -c12-13` +now=`date +"%A, %d of %B, %Y (%r)"` +if [ $hour -lt 12 ] +then + mess="Good Morning $LOGNAME, Have a nice day!" +fi + +if [ $hour -gt 12 -a $hour -le 16 ] +then + mess="Good Afternoon $LOGNAME" +fi + +if [ $hour -gt 16 -a $hour -le 18 ] +then + mess="Good Evening $LOGNAME" +fi +echo -e "$mess\nIt is $now" + diff --git a/ult/ult_9/dir-test.sh b/ult/ult_9/dir-test.sh new file mode 100644 index 0000000..11479ff --- /dev/null +++ b/ult/ult_9/dir-test.sh @@ -0,0 +1,5 @@ +#!/bin/bash +if test -d $1 +then + echo "Yes, the directory" $1 "is present" +fi diff --git a/ult/ult_9/emerald.mp3 b/ult/ult_9/emerald.mp3 new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/ult/ult_9/emerald.mp3 diff --git a/ult/ult_9/for-1.sh b/ult/ult_9/for-1.sh new file mode 100644 index 0000000..86545b7 --- /dev/null +++ b/ult/ult_9/for-1.sh @@ -0,0 +1,4 @@ +for i in {5..10} +do + echo $i +done diff --git a/ult/ult_9/for-2.sh b/ult/ult_9/for-2.sh new file mode 100644 index 0000000..ad34c9a --- /dev/null +++ b/ult/ult_9/for-2.sh @@ -0,0 +1,4 @@ +for i in `ls *.mp3` +do + echo "$i" +done diff --git a/ult/ult_9/for-3.sh b/ult/ult_9/for-3.sh new file mode 100644 index 0000000..8bb9f8d --- /dev/null +++ b/ult/ult_9/for-3.sh @@ -0,0 +1,4 @@ +for i in *.mp3 +do + echo "$i" +done diff --git a/ult/ult_9/for-5.sh b/ult/ult_9/for-5.sh new file mode 100644 index 0000000..dc17f64 --- /dev/null +++ b/ult/ult_9/for-5.sh @@ -0,0 +1,4 @@ +for i in *.mp3 +do + mv $i `echo $f|tr -s " " "-"|cut -d - -f 2-` +done diff --git a/ult/ult_9/premier.mp3 b/ult/ult_9/premier.mp3 new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/ult/ult_9/premier.mp3 diff --git a/ult/ult_9/script.rst b/ult/ult_9/script.rst new file mode 100644 index 0000000..7671e13 --- /dev/null +++ b/ult/ult_9/script.rst @@ -0,0 +1,441 @@ +.. Objectives +.. ---------- + + .. At the end of this tutorial, you will be able to: + + .. 1. Prepare scripts using 'Control Operators'. + .. 2. Understand what 'Environment Variables' are. + +.. Prerequisites +.. ------------- + +.. 1. Shell scripts & Variables + + +Script +------ + +.. L1 + +{{{ Show the first slide containing title, name of the production +team along with the logo of MHRD }}} + +.. R1 + +Hello friends and Welcome to the tutorial on +'Control structures and Operators'. + +.. L2 + +{{{ Show the 'Objectives' slide }}} + +.. R2 + +At the end of this tutorial, you will be able to, + + 1. Prepare scripts using 'Control Operators'. + 2. Use 'Environment Variables'. + +.. L3 + +{{{ Switch to the pre-requisite slide }}} + +.. R3 + +Before beginning this tutorial,we would suggest you to complete the +previous tutorials as being displayed currently. + +.. R4 + +We have many 'Control Structures and Operators' available in the linux bash. +Let us look at how to use them. +To write an 'if', or an 'if-else' construct, we need to check or test for a +condition(s). The ``test`` command allows us to test for condition(s). It has +a whole range of tests that can be performed. The man page of ``test`` +gives you the complete listing of various types of tests that can be performed +with it. + +Let's write a simple script with an ``if`` condition that tests whether a +directory with a particular name, exists or not. + +.. L4 + +.. L5 + +{{{ Show slide, 'if' }}} + +.. R5 + +Let us create a script named ``dir-test.sh`` with this code. +:: + + #!/bin/bash + if test -d $1 + then + echo "Yes, the directory" $1 "is present" + fi + +When the script is run with an argument, it will print a message, if a +directory with the said name exists in the current working directory. + +.. R6 + +Let's write a simple script which returns back whether the argument passed +is negative or not. + +.. L6 + +{{{ Open the file sign.sh and show }}} +:: + + #!/bin/bash + if test $1 -lt 0 + then + echo "number is negative" + else + echo "number is non-negative" + fi + +.. R7 + +We can run the file with a set of different inputs and see if it works. + +.. L7 + +{{{ Switch to terminal }}} +:: + + ./sign.sh -11 + +.. R8 + +Instead of using the ``test`` command, square brackets may also be used. + +.. L8 + +.. L9 + +{{{ Show slide, [ ] - alias for test }}} + +.. R9 + +Note that the spacing is important, when using the square brackets. +The left square bracket ( ``[`` ) should be followed by a space and the right +square bracket ( ``]`` ) should be preceded by a space. + +Let's create something interesting using the 'if-else' clause. Let's write a +script, that greets the user, based on the time. + +.. L10 + +{{{ Open the file clause.sh and show }}} +{{{ Highlight the required content wherever necessary, while narrating }}} + +.. R10 + +There are a couple of new things in this script. ``$LOGNAME`` is another +'environment variable', which has the login name of the user. The variables, +``hour`` and ``now`` are actually taking the output of the commands that +are placed in the back quotes. + +Now, let us see how to run loops in bash. We shall look at the ``for`` and +the ``while`` loops. + +.. L11 + +{{{ Show slide, 'for' }}} + +.. R11 + +Suppose we have a set of files, whose file-names contain numbers before the +text, say ``08 - Society.mp3``. We would like to rename these files by +removing the numbers before the text. How would we go about doing that? + +It is clear from the problem statement that we could loop over the list of +files and rename each of them. + +.. R12 + +First, let us look at a simple ``for`` loop, to understand how it works. + +.. L12 + +{{{ Switch to terminal }}} +:: + + for animal in rat cat dog man + do + echo $animal + done + +.. R13 + +We just wrote a list of animals, each name separated by a space +and then printed each name on a separate line. The variable ``animal`` is a +'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``. + +.. L13 + +.. R14 + +To generate a range of numbers and iterate over them, we do the following. + +.. L14 + +{{{ Open the script ``for-1.sh`` and show }}} + +.. R15 + +Now, let us run the script and see what we get, + +.. L15 + +{{{ Switch to terminal }}} +:: + + sh for-1.sh + +.. R16 + +Now, we use a ``for`` loop to list the files that we are interested in. + +.. L16 + +{{{ Open the script ``for-2.sh`` and show }}} +{{{ Switch to terminal }}} +:: + + sh for-2.sh + +.. R17 + +If the file-names contain spaces, ``for`` assumes, each word separated by a +space,to be a single item in the list and prints it in a separate line. We +could modify the script slightly to overcome this problem. + +.. L17 + +{{{ Open the script ``for-3.sh`` and show }}} +{{{ Switch to terminal }}} +:: + + sh for-3.sh + +.. R18 + +Now, we have each file name printed on a separate line. The file names are +in the form ``dd - Name.mp3`` and it has to be changed to the format +``Name.mp3``. Also, if the name has spaces, we wish to replace it with +hyphens. + +.. L18 + +{{{ Open the script ``for-4.sh`` and show }}} +{{{ Switch to terminal }}} +:: + + sh for-4.sh + +.. R19 + +Now, we simply replace the echo command with a ``mv`` command. + +.. L19 + +{{{ Open the script ``for-5.sh`` and show }}} +{{{ Switch to terminal }}} +:: + + sh for-5.sh + +.. R20 + +We see that we get our required output. All the files have been renamed and +the spaces are removed. +Now let us move ahead with ``while`` loop. +The ``while`` command allows us to continuously execute a block of commands +until the command that is controlling the loop is executing successfully. + +.. L20 + +.. R21 + +Let's start with the lamest example of a ''while'' loop. + +.. L21 + +{{{ Open the script ``while-1.sh`` and show }}} +{{{ Switch to terminal }}} +:: + + sh while-1.sh + +.. R22 + +This, as you can see, is an infinite loop that prints ``True``. + +Say, we wish to write a simple program that takes input from the user +and prints it back, until the input is ``quit``, which then quits the program. + +.. L22 + +{{{ Open the script ``while-2.sh`` and show }}} +{{{ Switch to terminal }}} +:: + + sh while-2.sh + +.. L23 + +{{{ Show slide, Environment Variables }}} + +.. R23 + +'Environment variables' are a way of passing information from the shell to the +programs that are run in it. Standard UNIX variables are split into two +categories,'Environment variables' and 'Shell variables'. In broad terms, +'Shell variables' apply only to the current instance of the shell and are +used to set short-term working conditions; 'Environment variables' have a +farther reaching significance, and are set at login, valid for the duration of +the session. By convention, 'Environment variables' have UPPER CASE and 'Shell +variables' have lower case names. + +You can see an example of environment variables in the slide. + +.. R24 + +To see all the variables and their values, we could use any of the +following, + +.. L24 + +{{{ Switch to terminal }}} +:: + + printenv | less + env + +.. R25 + +We have looked at the 'PATH' variable, in the previous tutorial. We shall now +use the ``export`` command to change it's value. + +.. L25 +:: + + export PATH=$PATH:$HOME/bin + +.. R26 + +Observe the difference in the value of 'PATH' variable before and after +modifying it. + +``export`` command is used to export a variable to the environment of all +the processes that are started from that shell. + +.. L26 + +.. L27 + +{{{ Switch to 'Summary' slide }}} + +.. R27 + +This brings us to the end of this tutorial. +In this tutorial, we have learnt to, + +1. Prepare scripts using control structures like ``if``, ``if-else``, + ``for`` and ``while``. +2. Use 'environment variables'. +3. Export a variable to the environment of all the processes, using + the ``export`` command. + +.. L28 + +{{{ Show self assessment questions slide }}} + +.. R28 + +Here are some self assessment questions for you to solve: + +1. Print the text ``dog man`` in such a way that the prompt continues after + the text. + +2. How can you add a new path variable ``/myscripts`` to $PATH variable ? + +.. L30 + +{{{ Solutions of self assessment questions on slide }}} + +.. R30 + +And the answers, + +1. We print the given text using the ``echo`` command by using an additional + option -n as, +:: + + $echo -n dog man + +2. We can add a new path variable by using the export command as, + +:: + + $export PATH=$PATH://myscripts + +.. L31 + +{{{ Show the SDES & FOSSEE slide }}} + +.. R31 + +Software Development techniques for Engineers and Scientists - SDES, is an +initiative by FOSSEE. For more information, please visit the given link. + +Free and Open-source Software for Science and Engineering Education - FOSSEE, is +based at IIT Bombay which is funded by MHRD as part of National Mission on +Education through ICT. + +.. L32 + +{{{ Show the ``About the Spoken Tutorial Project'' slide }}} + +.. R32 + +Watch the video available at the following link. It summarises the Spoken +Tutorial project.If you do not have good bandwidth, you can download and +watch it. + +.. L33 + +{{{ Show the `` Spoken Tutorial Workshops'' slide }}} + +.. R33 + +The Spoken Tutorial Project Team conducts workshops using spoken tutorials, +gives certificates to those who pass an online test. + +For more details, contact contact@spoken-tutorial.org + +.. L34 + +{{{ Show the ``Acknowledgements'' slide }}} + +.. R34 + +Spoken Tutorial Project is a part of the "Talk to a Teacher" project. +It is supported by the National Mission on Education through ICT, MHRD, +Government of India. More information on this mission is available at the +given link. + +.. L35 + +{{{ Show the Thank you slide }}} + +.. R35 + +Hope you have enjoyed this tutorial and found it useful. +Thank you! + diff --git a/ult/ult_9/sign.sh b/ult/ult_9/sign.sh new file mode 100644 index 0000000..246150d --- /dev/null +++ b/ult/ult_9/sign.sh @@ -0,0 +1,7 @@ +#!/bin/bash +if test $1 -lt 0 +then + echo "number is negative" +else + echo "number is non-negative" +fi diff --git a/ult/ult_9/society.mp3 b/ult/ult_9/society.mp3 new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/ult/ult_9/society.mp3 diff --git a/ult/ult_9/ult9.tex b/ult/ult_9/ult9.tex new file mode 100644 index 0000000..5201209 --- /dev/null +++ b/ult/ult_9/ult9.tex @@ -0,0 +1,221 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Using Linux Tools +% +% Author: FOSSEE +% Copyright (c) 2009, FOSSEE, IIT Bombay +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\documentclass[17pt,compress]{beamer} +\usepackage{beamerthemesplit} +\mode<presentation> +{ + \usetheme{Warsaw} + \useoutertheme{infolines} + \setbeamercovered{transparent} + \setbeamertemplate{navigation symbols}{} +} +% Taken from Fernando's slides. +\usepackage{ae,aecompl} +\usepackage[scaled=.95]{helvet} + +\usepackage[english]{babel} +\usepackage[latin1]{inputenc} +\usepackage[T1]{fontenc} + +% change the alerted colour to LimeGreen +\definecolor{LimeGreen}{RGB}{50,205,50} +\setbeamercolor{structure}{fg=LimeGreen} +\author[FOSSEE]{} +\institute[IIT Bombay]{} +\date[]{} +% \setbeamercovered{transparent} + +% theme split +\usepackage{verbatim} +\newenvironment{colorverbatim}[1][]% +{% +\color{blue} +\verbatim +}% +{% +\endverbatim +}% + +\usepackage{mathpazo,courier,euler} +\usepackage{listings} +\lstset{language=sh, + basicstyle=\ttfamily\bfseries, + showstringspaces=false, + keywordstyle=\color{black}\bfseries} + +% logo +\logo{\includegraphics[height=1.30 cm]{../images/3t-logo.pdf}} +\logo{\includegraphics[height=1.30 cm]{../images/fossee-logo.pdf} + +\hspace{7.5cm} +\includegraphics[scale=0.99]{../images/fossee-logo.pdf}\\ +\hspace{281pt} +\includegraphics[scale=0.80]{../images/3t-logo.pdf}} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% DOCUMENT STARTS +\begin{document} + +\sffamily \bfseries +\title +[Control structures and Operators] +{Control structures and Operators} +\author +[FOSSEE] +{\small Talk to a Teacher\\{\color{blue}\url{http://spoken-tutorial.org}}\\\vspace{0.25cm}National Mission on Education + through ICT\\{\color{blue}\url{ http://sakshat.ac.in}} \\ [0.8cm] + Contributed by FOSSEE Team \\IIT Bombay \\[0.3cm] +} + +% slide 1 +\begin{frame} + \titlepage +\end{frame} + +\begin{frame} +\frametitle{Objectives} +\label{sec-2} + +At the end of this tutorial, you will be able to, +\begin{itemize} +\item Prepare scripts using `Control Operators' +\item Use Environment Variables +\end{itemize} +\end{frame} + +\begin{frame} +\frametitle{Pre-requisites} +\label{sec-3} + +Spoken tutorial on - +\begin{itemize} +\item Shell scripts \& Variables +\end{itemize} +\end{frame} + +\begin{frame}[fragile] + \frametitle{\texttt{if}} + \begin{itemize} + \item Print message if directory exists in \texttt{pwd} + \end{itemize} + \begin{lstlisting} + #!/bin/bash + if test -d $1 + then + echo "Yes, the directory" $1 + "is present" + fi + \end{lstlisting} % $ +\end{frame} + +\begin{frame}[fragile] + \frametitle{\texttt{[ ]} - alias for \texttt{test}} + \begin{itemize} + \item Square brackets (\texttt{[]}) instead of \texttt{test} + \end{itemize} + \begin{lstlisting} + #!/bin/bash + if [ $1 -lt 0 ] + then + echo "number is negative" + else + echo "number is non-negative" + fi + \end{lstlisting} % $ +\end{frame} + +\begin{frame}[fragile] + \frametitle{Exercise} +\begin{itemize} +\item Given a set of \texttt{.mp3} files, with names beginning with numbers + followed by text -- eg: \texttt{08 - Society.mp3} + +\begin{itemize} +\item Rename the files to have just the names +\item Replace any spaces in the name with hyphens +\end{itemize} +\end{itemize} +\end{frame} + +% \begin{itemize} +% \item Loop over the list of files +% \item Process the names, to get new names +% \item Rename the files +% \end{itemize} +%\end{frame} + +\begin{frame}[fragile] + \frametitle{Shell Variables vs. Environment variables} + %\texttt{Environment variables vs. Shell variables} +\begin{table} +\begin{tabular}{|l|l|} +\hline +Shell var. & Environment var.\\\hline +only current instance & valid for the whole\\ +of the shell & whole session\\\hline +UPPER CASE & lower case\\\hline +\end{tabular} +\end{table} +\end{frame} + +\begin{frame} +\frametitle{Summary} +\label{sec-8} + + In this tutorial, we have learnt to, + + +\begin{itemize} +\item Prepare scripts using control structures -- ``if'', ``if-else'', + ``for'' \& ``while'' +\item Use environment variables +\item Export variable to environment of all processes, using + ``export'' command +\end{itemize} +\end{frame} +\begin{frame}[fragile] +\frametitle{Evaluation} +\label{sec-9} + + +\begin{enumerate} +\item Print the text ``dog man'' in such a way that the prompt continues after +the text. +\vspace{8pt} +\item How can you add a new path variable ``\texttt{/myscripts}'' to \$PATH variable ? +\end{enumerate} +\end{frame} +\begin{frame} +\frametitle{Solutions} +\label{sec-10} + + +\begin{enumerate} +\item \$ echo -n dog man +\vspace{15pt} +\item \$export PATH=\$PATH://myscripts +\end{enumerate} +\end{frame} +\begin{frame} + + \begin{block}{} + \begin{center} + {\Large THANK YOU!} + \end{center} + \end{block} +\begin{block}{} + \begin{center} + For more Information, visit our website\\ + {\color{blue}\url{http://fossee.in/}} + \end{center} + \end{block} +\end{frame} + + +\end{document} + + diff --git a/ult/ult_9/while-1.sh b/ult/ult_9/while-1.sh new file mode 100644 index 0000000..485e167 --- /dev/null +++ b/ult/ult_9/while-1.sh @@ -0,0 +1,4 @@ +while true +do + echo "True" +done diff --git a/ult/ult_9/while-2.sh b/ult/ult_9/while-2.sh new file mode 100644 index 0000000..5fbdd11 --- /dev/null +++ b/ult/ult_9/while-2.sh @@ -0,0 +1,7 @@ +while [ "$variable" != "quit" ] +do + read variable + echo "Input - $variable" +done +exit 0 + |