Starting from:

$30

CSC3320- Lab 5: (Out-Lab) Solved

Purpose: Learn how to write basic shell script.  

In Chapter 2 and 3, you have learned a list of utilities. However, each time we could only type a single command on command line in terminal. It is inconvenient sometimes when a task has to been accomplished by multiple commands. For example, if the task needs to be repeated, you may have to restart the execution of the list of commands by typing the command one by one. For this reason, the shell script file is used to store the commands interpreted by shell. It is more than a regular file containing only the command. You can even write for loop, if else and switch case statement in the shell script. The shell script file can be executed directly by providing the name of it on command line.    

Write a report by answering the questions and upload the report 

(named as Lab5_P1_FirstNameLastName.pdf or  

Lab5_P1_FirstNameLastName.doc) to google classroom.  This lab assignment is related to the slides   

 

#12 to #14 in chapter 4 Part

           1:  

Now it is your turn to create your first shell script file by following the steps below.  


Step 1: Go to your home directory and create a new file named as simple.sh (vi simple.sh or nano simple.sh), then include following lines in your simple.sh.  

Question 1) : What did you see in the output of step 3?  

Question 5): Is "Simple Script" a comment? If not, what is the meaning of it or why we use it?  

Question 6): Is "#!/bin/bash" a comment? If not, what is the meaning of it or why we use it in first line?  

Part 2:  

To discard the ./ before the script file name when executing it, we need to change the PATH variable's value and add current working directory into it.  

Step 7: Print out the value stored in PATH variable.  

Question 7) : How many directories you can find in the output? Note: the directories are separated by colon.  

Step 8: Try command below to insert current working directory at the beginning of the string value stored in PATH variable. $PATH=.:$PATH  

Step 9: Execute simple.sh again by trying following command. $simple.sh  

$ simple.sh  

Question 8) : Can you find errors prompted in step 9 ? If not, please briefly describe why there is no need to put ./ before the file name.  

Step 10: Log out the connection to the snowball server and reconnect to it. Or simply close your terminal and then reopen your terminal.  

Step 11: Print out the value stored in PATH variable again.  Question 9: Can you find the current working directory . in the PATH variable?  

Step 11: Execute simple.sh again by trying following command. $simple.sh  

$ simple.sh  

Question 10) : Can you find errors prompted in step 11 ? If yes, please explain why?  

Part 3 - Optional:  

Questions:  

Can you find some errors when executing the command in step 4? If yes, please point out which lines contain errors. Think about the correction in your next lab. Before the correction, you could pre-view the slides #15 - #24 in Chapter 4.  

Hints:  


Following is a sample of the output once all the errors are corrected
$ ./checkError.sh bbello1 Try to find out some errors!!! checkError.sh Result  

The result has been sent to bbello1@student.gsu.edu Congratulations! You have corrected all the errors!  

You can use cat -n checkError.sh to check line numbers.
You may need to use CTRL-C to terminate the execution of the command, especially for the script file with errors.

More products