\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[a4paper, margin=0.75in]{geometry}

% set up hyperlink coloring
\usepackage{hyperref}
\hypersetup{
    colorlinks=true,
    linkcolor=blue,
    filecolor=magenta,
    urlcolor=cyan
}

\setlength{\parindent}{0pt} % no indentation

\renewcommand{\familydefault}{\sfdefault} % default to sans serif

%%%%%%%%%%%%%%%%
\begin{document}

\title{Homework 2\\Shells, Environment, and Scripting}
\author{EECS 201 Winter 2020}
\date{}
\maketitle

\section*{Submission Instructions}
Answer the bolded text that begins with a bolded number e.g. ``\textbf{1}'', ``\textbf{2}''.
Submit this assignment on \href{https://gradescope.com}{Gradescope}.
\textbf{When submitting please select the right pages for each question or we will not grade the question}.
You may find the free online tool \href{https://www.pdfescape.com}{PDFescape} helpful to edit and fill out this PDF.
You may also print, handwrite, and scan this assignment.
\\\\
If you feel enterprising, you can edit the TeX file directly, compile it to a PDF, and submit that!
I ask that if you do so, please make the answer text stand out from the rest of the homework.

\section{Understanding your \texttt{PATH}}
In a terminal, type \texttt{PATH=} (just hit enter after the equal sign, no
space characters anywhere). Try to use the terminal like normal (try running
\texttt{ls}). What happened?

\textbf{1: Give an example of a command that used to work but now doesn't:}
\vspace{1.5cm}

\textbf{2: Can you still run this command with an empty \texttt{PATH}? How?}
\vspace{1.5cm}

\textbf{3: Give an example of a command that works the same even with an empty
\texttt{PATH}. Why does this command still work?}
\vspace{1.5cm}


\section{Playing with the shell a bit: Special Variables}

Bash has quite a few special variables that can be very useful when writing
scripts or while working at the terminal.

\textbf{1: What does the variable \texttt{\$?} do? Give an example where this
value is useful}
\vspace{3cm}

\textbf{2: What does the variable \texttt{\$1} do? Give an example where this
value is useful}
\vspace{3cm}


\newpage
\section{Basic Scripting}

Recall from lecture that scripting is really just programming, only in a very
high-level language. Interestingly, \texttt{sh} is probably one of the oldest
languages in regular use today.
\\\\
\texttt{make} is a good tool for build systems, but we can actually use some
basic scripting to accomplish a lot of the same things.
First, write a simple C program that prints ``Hello World!''.
Write a shell script named \texttt{build.sh} that performs the following
actions:
\begin{enumerate}
  \item Compile your program
  \item Runs your program
  \item Verifies that your program outputs exactly the string ``Hello World!''
    \begin{itemize}
      \item There are good utilities that check the \texttt{\underline{diff}}erence of two
        files. They could be helpful.
    \end{itemize}
  \item Prints the string ``All tests passed.'' if the output is correct, or
    prints ``Test failed. Expected output $>>$Hello World$<<$, got
    output $>>$\{the program output\}$<<$''.
\end{enumerate}
\textbf{1: How would you make the script executable by invoking its path (e.g. \texttt{\$ ./build.sh})}?
\vspace{1.5cm}

\textbf{2: Copy the output of \texttt{cat build.sh} here:}


\vfill

\section{Controlling your environment}
Suppose that you have a directory called \texttt{scripts} in your home directory
to hold all the neat scripts you've written.
If you wanted to invoke these scripts without explicitly specifying the scripts' paths,
you would add that directory to the \texttt{PATH} variable.

\textbf{1: Describe how you would set up your system to modify your \texttt{PATH}
        to automatically to include a \texttt{scripts} directory in your home directory
        every time you open a new terminal (what file would you change
        and what would you put in it?)}
\vspace{3cm}

\textbf{2: Roughly how long did you spend on this assignment? \rule{5cm}{0.1mm}}

\end{document}
