CS699: Software Foundation Lab
Lab 2: Bash Scripting and Git Usage
Part 2 - Math using Bash
Aim
- Write a Bash or Shell (
.sh
) script to take an integer list of any length as a command line argument. - Arguments should be space separated as shown below.
- Your script
lab2_q2.sh
should be able to display the length of the array in the first line and sum of the cubes of each number in the second line. There should be only two lines output, no space, no extra characters. - For example, to execute the script:
Output of above command should be exactly:./lab2_q2.sh 1 2 3 4 5
5 225
- Explanation: 13 + 23 + 33 + 43 + 53 = 225
Given
- Skeleton program file:
lab2_q2.sh
Procedure
-
Visit your private repository for Part 2 that you must have received access to after performing the steps as mentioned in Introduction to GitHub Classroom document.
-
Copy the Clone HTTPS URL of your repository as shown in Figure 1.
Figure 1: Copy Private Repository URL from the GitHub website.
-
Open Terminal and navigate to the directory where you want to clone your repository.
-
Now, clone the repository into your machine using the following command:
https://github.com/CS699-IITB-Autumn-2021/lab2-q2-math-using-bash-<username>.git
-
Navigate to the cloned repo folder and modify the provided
lab2_q2.sh
file. Make this file executable and run as mentioned in Aim section. -
After you are satisfied with your output and want to push your code to the repo, follow the below steps:
-
Run,
git status
to check the status of your file. You will observe that state is modified.
-
Now run,
git add lab2_q2.sh
to stage the modified file in the directory.
-
Run
git status
again, to verify whether the file is staged.
-
Run
git commit -m "type message for your commit here"
to commit the file which is staged.
-
Run
git status
to verify that your working tree is clean.
-
Lastly, run
git push origin master
Make sure that you enter your GitHub username and password.
-
-
If your code passed all the test cases, you will observe a ✅ next to the commit as shown in Figure 2.
Figure 2: Successful attempt to clear all the test cases.
-
You can review the result of all your commits by visiting the Actions tab in your Assignment repository as shown in Figure 3.
Figure 3: Reviewing the result of each commit on GitHub.
-
Voila! You have now successfully completed the Part 2.
To check the content of folder q2
:
$ ls -A q2/
Output of above command should look like:
q2
└── lab2_q2.sh
Part 2 will be checked via auto-grader, so make sure the filename is not changed and folder q2
consists of just one file.
References
When you see a door with push sign, pull first to avoid conflicts!