$40
Purpose: Learn how to correct a shell script and write more
complicated shell scripts.
Part 1:
In order to finish the tasks in this lab, you must connect to snowball server to copy my checkError.sh
$cp
/home/yye10/public/checkError.sh
checkError.sh
In Lab 5, you may have tried the shell script checkError.sh in part 3. However, there are four errors on four different lines in that shell script. Please correct all the four errors by writing down the line
number, the error and the correction as below:
Line #: Error: Correction:
Note: please use cat -n to check the line numbers.
Hints:
Following is a sample of the output once all the errors are corrected $ ./checkError.sh ylong4
Try to find out some errors!!!
checkError.sh Result
The result has been sent to ylong4@student.gsu.edu
Congratulations! You have corrected all the errors!
You would also receive an email sent from your snowball account once all the errors are corrected.
You may need to use CTRL-C to terminate the execution of the command, especially for the script file with errors.
Part 2:
Write a single shell script hello.sh which can finish the list of tasks as below:
Greet user. E.g. Welcome to computer science society.
Contain a comment section with your name, and email address.
Print the date.
Print the number of directories in /home .
Print the value of variables PATH, USER and SHELL.
Print your disk usage (df).
Print Please, could you loan me $25.00?
Print if x = 2, x * x = 4 , x / 2 = 1
List all the .sh files with c at the beginning of the file name in current working
Tell the user Good bye and the current hour (see manual page of date command refer to the webpage at http://www.thegeekstuff.com/2013/05/date-commandexamples )
Include the content of hello.sh in your answer sheet. Besides, please also upload hello.sh as a separated file.
Upload your answer sheet to the folder named “Lab 6_P1” of the dropbox in the iCollege
system. Name your file in the format of Lab6_P1_FirstnameLastname.pdf/doc
Purpose: Learn the differences between writing a Bourne shell script and Java program. Learn how to use command argument in a Bourne Shell script. Learn how to compile and run Java and C programs in Unix terminal.
Part A:
Please complete the tasks in following table step by step and finish the questions below the table.
$./foo.sh
Note: when typing the shell script in your terminal, please be very careful of the spaces.
1
Questions:
Attach a screenshot of the output in step 4.
Describe what does the shell script foo.sh do?
Part B:
Step 1: Edit your foo.sh and change “ -le 3 ” to “ -le $1 ” .
Step 2: When finished, save the foo.sh and exit editor. Then try executing it again by typing following command.
$./foo.sh 5
Question:
Attach a screenshot of the output.
Part C:
Step 1 : Edit your foo.sh in part B by making following modifications:
Add two new lines below between line “i=1” and line “while [ $i -le $1 ]”
echo please input a number read num
Change “ -le $1 ” to “ -le $num ” .
Step 2: When finished, save the foo.sh and exit editor. Then try executing it again by typing following command and type 5 as the input of the number. $./foo.sh
Question:
Attach a screenshot of the output.
Part D:
Write a Java program named foo.java to accomplish the same task as that in foo.sh of Part
A.
Question:
2
Then put the source code of foo.java in your answer sheet.
Part E:
Create and run Kernighan and Ritchie’s famous “hello,world” program.
Step 1: Go to your home directory (cd ~) and create a new file named as hello.c (vi hello.c
Questions:
Attach a screenshot of the output in step 4.
Try following command to compile and link hello.c And tell what new file is generated after this command?
$cc -o hello hello.c
Try command below and attach a screenshot of the output.
$./hello
Now write a new C program named as c based on hello.c. In this program, print out your first name and last name instead of “Hello,world”. For example, the output could be “My name is Yuan Long”.
Execute your myName.c and attach a screenshot of the output. Then write the source code
of myName.c in your answer sheet and upload your file myName.c to classroom.