Week 1 - Setup, tools, CLI and Git

Intro to the CLI

Files and folders

Paths

Basic scripting

Node.js Setup

VSCode setup

Intro to Git

Intro to Github

Markdown

Practice

Assignment

Back to core program

Creating basic scripts

So far we learned many useful commands to interact with your computer. Let’s combine a few commands together to write a small script to automate something simple.

Environment variables

Environment variables are dynamic values in your operating system that programs can access to share information like configuration with other programs.

Your system already has a few environment variables defined. Here are some of them:

<aside> ⌨️

Hands on: Open the terminal and print those variables. For example: echo $HOME

</aside>

Environment variables are a great way to share information between different programs. For example, one program sets an environment variable with some result, and then another program reads the same variable to find out what the first program produced.

You can also set your own custom environment variables:

export MY_VARABLE="some value"

It's common practice to write environment variable names in upper case with underscores instead of spaces. This makes them stand out to developers when writing software.

Your first shell script

Create a new file called hello.sh with the following content:

#!/bin/bash
echo "Hello, world!"

Save the file and now let’s run the file using the command:

sh hello.sh

You should be able to see the current output in the terminal:

Hello, world!

<aside> 🎉

You just wrote and ran your first bash script!

</aside>

Making it more complicated

Now we are ready to combine a few commands into one file to make a fully automated script:

#!/bin/bash
# Part 1
echo "Welcome! Your home folder is: $HOME"
mkdir project
cd project
date >> message.txt
echo "Hello everyone" >> message.txt
cp message.txt message2.txt

# Part 2
mkdir ../project-2 
mv message2.txt ../project-2
cd ../project-2
echo "All done"

In a shell script, each line will be executed individually.

<aside> ⌨️

Hands on: Read the code above and try to follow along. What will the end result be? Afterwards, run the script and inspect the result.

</aside>


The HackYourFuture curriculum is licensed under CC BY-NC-SA 4.0 **

CC BY-NC-SA 4.0 Icons

*https://hackyourfuture.net/*