Lab 3 - The Bash Shell
Video here
Pre Work:
- Open the file manager and navigate to the
labs
folder/directory inside the cis106 repository(~/cis106/labs/)
- Create a folder/directory called
lab3
- Open VS Code and open the
cis106
directory/folder inside VS Code - Create a file called
lab3.md
inside thelab3
folder/directory - Add the following markdown, save the file, close vs code, and start your lab
---
Student: your name
semester: Spring 24
Assignment: Lab 3
---
# Lab 3 Submission
## Question 2
![q2](q2.1.png)
## Question 3
![q3](q3.png)
## Challenge Question
![q4](q4.png)
## Script Source code:
[lab3](lab3-script.sh)
Question 1: Using Ubuntu’s Desktop Environment (GNOME)
Appearance
- Download a wallpaper that you like. You can use this website for downloading wallpapers: wallheaven.cc
- Create a directory/folder in the
Pictures
directory calledwallpapers
- Save the file in this newly created directory. Make sure to change the name to something more descriptive of the image.
- Right-click on the desktop and change the wallpaper to the one you downloaded recently.
- Add the following applications to the favorites bar:
- VS Code
- Tilix
- Customize the favorites bar to your liking
- Change its position
- Remove any application you do not use regularly
- Do you like the panel mode or the dock mode?
- How about the icon size?
Custom Font
- Download one of the following fonts from this website:
- Hack
- FiraCode
- Meslo
- Source Code Pro
- Terminus
- Monoid
- Noto
- Iosevka
Note: you can use this website to preview the font. Choose one you like and download it.
- Install the font
- Create a hidden folder/directory in your home directory called
.fonts
(In Linux, hidden folders start with a period therefore to create a hidden folder all you need to do is start its name with a period) - Enable hidden folder view in the file manager by pressing CTRL + H. You should notice that a lot of more hidden folders appear.
- Decompress the
font.zip
file you downloaded earlier and move all the.ttf
files to the.fonts
directory. - Open a terminal and type the command
fc-cache -fv
. This command will scan your system for new fonts.
- Create a hidden folder/directory in your home directory called
- Close the terminal. Open the file manager and press CTRL + H again so we can hide the hidden folders/directories again. You don’t want to mistakenly delete those later!
- Open the terminal and type the following command:
echo "hello world"
This question does no require screenshot
Question 2: Working with BASH in the terminal emulator
Note: I use tilix but you are welcome to use any other terminal emulator.
- Open Tilix and then click on the hamburger menu (≡) and then on preference. Ignore the error message
- Click on appearance. Enable “Use a wide handle for splitters”
- Split the terminal in 2 horizontally. Open the man page of the
echo
command in one of the terminals. - Resize the terminal window so that you have enough space to work on both.
- Using the man page of echo figure out how to do the following:
- Display a line of text without the new line
- Display a line of text that includes a horizontal tab
- Display 2 lines of text in a single echo command
- Display 2 lines of text in a single echo command, with the second line starting with a tab
- Display 2 lines of text in a single echo command that starts with a tab
Take a screenshot of the terminal showing all the commands that you used and the man page open. Save your screenshot as q2.1.png
Question 3: Write a basic shell script
- Open the text editor app (Gnome Text)
- Click on the gear icon (⚙) then
- Enable “Show line numbers”
- Enable “Show right margin”
- disable “Check spelling”
- In Spaces Per Tab, set it to “4”
- Click on the hamburger menu (≡) and then properties
- Pick a a theme that you like
- Enable custom font and pick the font you downloaded earlier. Adjust the font size to your liking.
- Enable highlight current line
- Type the following line:
#!/bin/bash
(double-check your spelling) - Save the file as:
lab3-script1.sh
in thelab3
folder/directory insidecis106/labs/
- Add the following lines, then save the script.
echo "This is a shell script,"
echo -n "This script will print the current date"
date
echo "This is the machine's name:"
uname -n
echo "This is the current user:"
echo $USER
echo "This is the current date"
date +"%A, %B %d %R %Z"
- Add the following comments at the top after the shell declaration/shebang
#!/bin/bash
# Author: your name
# Date: current date in format mm/dd/yy
# Description: This is a basic script that
# uses environment variables and the date command
- Save the script and close the text editor
- Open a terminal and type the following commands to execute the script:
bash ~/cis106/labs/lab3/lab3-script.sh
Take a screenshot of the terminal showing the output of the script. Double-check your spelling and follow every step correctly if you get any error messages.
Question 4: Challenge Question
Write a shell script that displays the following output:
Tips:
- You will need to read the man page of the
echo
,uname
, anddate
,df
,free
andfiglet
commands. - You can use the
cheat
command - Save the script in the same directory/folder as you saved the question 3 script
~/cis106/labs/lab3/
- Name the script
challenge_lab3.sh
- The command to run the script is
bash ~/cis106/labs/lab3/challenge_lab3.sh
if this does not work, it is because you saved the script in the wrong folder. Retrace your steps to troubleshoot. - You must complete this question alone. I cannot provide assistance here. Everything you need to complete this challenge has been covered in this lab and in the presentations. While I cannot provide you with assistance answering the question, I can provide extra explanations or clarifications.
NOTE: This script must use the
echo
,uname
, anddate
,df
,free
andfiglet
command. Any other solution that does not involve these commands will not be accepted and you will receive 0 for this question. No exceptions!
What will you submit:
- Place and properly label (using headings) all the screenshots you took. See the markdown I gave you at the beginning of this document
- Convert the file to pdf
- Push everything to github
- In Blackboard, submit the pdf file
lab3.pdf
Note: I will read your script from github. If the script is not there, you will not receive credit.
How I will grade you:
- I will navigate to your GitHub repository and read your script.
- I will download your script and run it on my machine.
- If your script runs and I get the same output as the screenshot, you will get full credit for the challenge question. Otherwise, partial credit will be awarded.
- Every question in this lab is worth 25 points.
Special Note
You are going to be using the git commands a lot. Here is a quick reference:
git clone repository/url/here
: is the command to clone a repository where cloning means downloading a repository to your computergit pull
: to pull/synchronize your repository from github to your local machine. Always run this command BEFORE you start working VS Codegit add .
: to track all the changes made to your file.git commit -m "label for your changes here"
: this command will label all the changes you added with theadd
commandgit push
: will send all your changes to your github repository
Always run the commands in this order:
pull
=>add
=>commit
=>push
Never use the github website to make changes to your repository unless you know what you are doing and can remember to pull the changes before working on your local repository!