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