$29.99
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:
1) Attach a screenshot of the output in step 4.
2) 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:
1) Attach a screenshot of the output in step 4.
2) Try following command to compile and link hello.c again. And tell what new file is generated after this command?
$cc -o hello hello.c
3) Try command below and attach a screenshot of the output.
$./hello
4) Now write a new C program named as myName.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.
3
Submssion:
Note: Please follow the instructions below step by step, and then write a report by answering the questions and upload the report
(named as Lab6_FirstNameLastName.pdf or
Lab6_FirstNameLastName.doc) to Google Classroom, under the rubric Lab 6 Out-of-lab Assignment.
Please add the lab assignment NUMBER and your NAME at the
top of your file sheet.
4