Skip to main content

Lab 3 - Scripting Part 1

In this lab, we will explore the basics of bash scripting by creating several simple but fundamental scripts that demonstrate essential programming concepts. Through these exercises, you will learn how to write a "hello world" script, interact with users via input, and perform conditional operations like checking if a number is even or odd. Additionally, we will practice file manipulation by creating a script to search for a specific string within a file. Lastly, we will tackle a more advanced assignment—building a phonebook script to manage and search contact information. These tasks will lay the foundation for understanding how to write practical and efficient shell scripts to automate processes and manage data.

Objectives

  1. Read through the following link up to the "Script Lab Assignment Section" [Berkely.edu]
  2. Create a "Hello World" bash script
  3. Create a bash script capable of receiving user input
  4. Create a bash script to show if a number is even or odd
  5. Create a bash script that checks a given file for a string and prints true if found
  6. Complete the phonebook assignment as dictated in the above

Initial Setup

You should create a directory in your home path called “scripts”. Don’t forget to run the chmod +x filename command on these scripts to make them executable.

Demonstrate User Input

Create a bash script capable of taking user input. This script should prompt the user for their age, then when given print out a statement saying "The user is X years old". If you would like, you can leverage loops to make it ask continuously