<style> .markdown-body h1:first-of-type { margin-top: 24px; } .markdown-body h1 { margin-top: 64px; } .markdown-body h1 + h2 { margin-top: 32px; } .markdown-body h2 { margin-top: 48px; } .markdown-body h2.topics { font-size: 1.8em; border-bottom: none; } .markdown-body h3 { color: cornflowerblue; } .markdown-body p strong { font-weight: normal; color: red; } .exercise { font-size: 150%; font-weight: bold; color: rgb(227,112,183); } .note { color: red; } </style> # ACIT 1515 - Lesson 1 Welcome to ACIT 1515 Scripting for IT! Each week of the course will follow the same basic lesson structure: 1. Review of material from the previous week if necessary 2. Written (on paper!) quiz questions on the previous week's material 3. A short hands-on lecture to recap new material Once the above are complete, you'll be given time in-class to start on the weekly assignment. All material on the quizzes will be taken directly from these online notes and the in-class assignments. <h2 class="topics">Topics</h2> - [Terminal](#Terminal) - [Python and Environment Variables](#Python-and-Environment-Variables) - [Syntax Errors](#Syntax-Errors) - [Linux Command Reference](#Linux-Command-Reference) - [Brief Introduction to Git](#Brief-Introduction-to-Git) - [Assignment 1](#Assignment-1) ## Terminal The terminal is a text-based interface to your operating system - it is essentially the file explorer, with no graphical components (icons, windows etc.). On Windows, you can open the terminal by hitting the Windows key, then searching for 'Terminal'. On Mac, the terminal is located in the Utilities folder inside the Applications folder. By default, when you open the terminal app you will start in your home folder and see something similar to the following: Windows example: ```C:\Users\You>``` (On the C drive, in the Users folder, inside a folder with your username) Mac example: ```you@your-Macbook-Pro ~ %``` (On the hard drive, in the Users folder, insider a folder with your username) Linux example: ```you@your-machine:~$``` The lines above that show information about your system and where you are located in your filesystem are called the ==prompt== ### Prompt A ==prompt== is the input field in the terminal - the place where you can type ==commands==. The examples above are your _operating system_ prompt, and only operating system commands can be used when this prompt is active. As you become more comfortable with the terminal you will start to see other prompts, each with their own use. As noted [below](#Python-REPL), Python has its own prompt where only Python commands can be used. ### Commands Here is an example linux prompt and command: ```you@your-machine:$ ls``` ```you@your-machine:$``` is the prompt, and ```ls``` is an operating system command that lists all the files in the current folder And another example: ```you@your-machine:$ python3``` ```you@your-machine:$``` is the prompt, and ```python3``` is an operating system command that starts the Python interpreter. The Python interpreter is the program responsible for running your code. ### Arguments Commands can take ==arguments== ```you@your-machine:$ python3 test.py``` In this example, ```python3``` is the command, and ```test.py``` is the ==argument== - typed together this command and argument will run a python file in the current folder named ```test.py``` (if it exists!) Running the python command with no arguments starts an interactive Python environment where you can test out small bits of Python. ```you@your-machine:$ python3``` ### Python REPL ```>>>``` is the prompt for an interactive Python environment, called the REPL (read-evaluate-print-loop), and it only accepts Python commands, not operating system commands. Most of the time you **do not want to be in the Python REPL**. Instead, you will create files with the .py extension and run them using the terminal or a text editor. To exit the REPL and get back to the operating system prompt, you must type `exit()` or `quit()` (followed by the enter key) ### Aliases Commands can have ==aliases== It is possible to configure your system so that different commands run the same application. For example, you may need/want to use any one of: ```py``` ```python``` ```python3``` to run the Python interpreter (the program that runs your Python code), but you may be able to use more than one! Typically, ```py``` is used as an ==alias== for ```python3```, meaning that both commands do the same thing (they run the Python interpreter) To keep things simple, we want to only have one version of Python installed, and we will set up aliases so that any of these possible commands (py, python, and python3) will work correctly on your system. ## Python and Environment Variables After successfully running the Python installer, you still _may_ need to do some operating system configuration before you can start to use it. The terminal relies on an operating system variable called ==Path== to find applications and languages like Python on your computer. The ==Path== variable is just a list of folders that are searched when an operating system command is run. For example, when you type the command: ```you@your-machine:$ python3 --version``` (to print information about the currently installed version of Python), the operating system will look through every folder in the ==Path== to find the Python interpreter. If the folder that Python is installed into is not added to the Path, Python may not run! We will walk through configuring your Path in class if necessary. ## Syntax Errors When you run a .py file, _before any code is executed_ it must first be compiled into bytecode (think of bytecode as a set of instructions for the Python interpreter). During this compilation step, your code is checked for ==syntax errors==. Syntax errors mean that something in your code is invalid; you forgot a colon, didn't close quotation marks, and so on. If syntax errors are found, the code in your file will never run. Below is an example using the ```print()``` function, which we can use to output text in the terminal *from our script*. The code: ```python= print('Hello World) ``` results in the error ```SyntaxError: unterminated string literal``` which, in human terms, means that you forgot to put a closing single quote after World. Note that although the error appears in the terminal, the words 'Hello World' are not printed! As mentioned above, when syntax errors in your files are detected, the code is not actually run. The corrected code would look like the following: ```python= print('Hello World') ``` As you go through the course you will need to learn what these errors mean, and be able to find and correct them in your files. ## Linux Command Reference Listed below are a few useful terminal commands to help you navigate around the filesystem, create and rename files and folders ### cd change directory (N.B. directory = folder) ```cd ``` go to your home folder ```cd ../``` go up one folder ```cd ../../``` go up two folders ```cd ./acit1515``` go into a folder named acit1515 in the current folder ```cd ~``` go to your home folder (~ is an alias for the path to your home folder) ```cd ~/acit1515``` go to a folder named acit1515 in your home folder (i.e. /home/you/acit1515) ### pwd present working directory ```pwd``` takes zero arguments and returns the path you are currently located at ### ls list directory contents ```ls``` list all files and folders in the current folder ```ls ./acit1515``` list all files and folders in a folder named acit1515 that is located in the current folder ```ls ~``` list all files and folders in your home folder ### mv move or rename a file ```mv test.txt testing.txt``` rename a file in the current folder called test.txt to testing.txt ```mv test.txt ~/test.txt``` move a file in the current folder called test.txt to the home folder (e.g. /home/you) ### mkdir make directory ```mkdir acit1515``` create a folder named acit1515 in the current folder ```mkdir ~/acit1515``` create a folder named acit1515 in the home folder ## Brief Introduction to Git We will be using [Git](https://git-scm.com/video/what-is-git) and [Github](https://github.com/) (free online hosting of Git repositories) for downloading assingment starter code and for making your assignment submissions. For this course we'll use a very limited subset of the functionality of Git and Github - please read through the introduction here: https://hackmd.io/@charris17/git-reference ## Assignment 1 Assignment 1 is intended as an introduction to the type of scripting and automation we will be focusing on in this course, as well as a way to ensure that everyone has their development environment (Linux, Python, and Git) set up. Please ensure that you have signed up for a Github account (preferably with a username that includes either your real name or student ID) so that you are able to download the starter code. Access to the starter code itself, and an explanation of the requirements will be given to you in-class.