diff options
Diffstat (limited to 'ult')
-rw-r--r-- | ult/handout.rst | 35 | ||||
-rw-r--r-- | ult/ult.tex | 15 |
2 files changed, 50 insertions, 0 deletions
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 @@ -1013,6 +1013,21 @@ \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} \item \texttt{echo} command prints out messages |