Assignment 8 – Shell Script

Task A (Correct script (25 points) + result/output after executing the script (25 points)-
Conditional Statement
Write a shell script using nano or vi editor (eg, vi scriptname.sh) like below, that performs
the following task:
1. Add the Shebang (#!/bin/bash) as the first line in your script.
2. Read a number using read function
3. Using if statement, check if the input number is greater than 10, then print the message
“Input number is greater than 10”.
4. If the number is not greater than 10, then print the message, “Input number is not
greater than 10”.

Task B (Correct script (25 points) + result/output after executing the script (25 points) –
Shell Script to Create a new file
Write a shell script using nano or vi editor (eg, nano scriptname.sh) like below, that
performs the following task:
1. Add the Shebang (#!/bin/bash) as the first line in your script.
2. Reads the name of the file to check for a filename that exists.
3. Check whether the given input is a directory or regular file.
4. If the input is a directory and exists, then display the message “Directory exists”.
5. If the input is a regular file, then display the message “It is a regular file, and the file
exists” and display the contents of the file.
6. If the given input name in step-1 doesn’t exist, then create the new file with the given
name in step-1.

(Extra credit: 10 points) Add your name to the file (using redirection operator ‘>’) and
display the contents for the newly created file.
7. Save and exit the editor and remember to make the script executable using the
command chmod +x scriptname.sh)

Reflection
This assignment gave me hands-on experience writing shell scripts reading user input and checking file types in Linux. I found it helpful to reinforce how scripts interact with the file system.

Leave a Reply

Your email address will not be published. Required fields are marked *