Step-1: Use vi or nano editor to write your script (Ex, nano lkopa.sh) for the following tasks.
Step-2: After saving the script, save and exit out of the editor and make the script executable by adding execute permission ( chmod +x lkopa.sh)
Step-3: Run your script using ./lkopa.sh
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, nano lkopa.sh) like below, that performs the following task:
- Add the Shebang (#!/bin/bash) as the first line in your script.
- Read a number using read function
- Using if statement, check if the input number is less than 10, then print the message “Input number is greater than 10.
- 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 lkopa.sh) like below, that performs the following task:
- Add the Shebang (#!/bin/bash) as the first line in your script.
- Reads the name of the file to check for a filename that exists.
- Check whether the given input is a directory or regular file.
- If the input is a directory and exists, then display the message “Directory exists”.
- 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.
- 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. - Save and exit the editor and remember to make the script executable using the command chmod +x lkopa.sh)
Extra Credit(15 points)- Check Directory Write a script like below that
- Reads Two variables- your name and the name of the directory as input.
- Your script should check for the validity of the given directory name, if the entered filename is a directory, then display its contents
- If the directory doesn’t exist, then print an error message “Sorry, the entered directory name is not a valid directory name.”
- You need to execute your script and test the following directories to test with your script
- /etc/systemd
- /home
- A directory that does not exist
Display the contents for the directories you have entered