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:
    ./lab2_q2.sh 1 2 3 4 5
    
    Output of above command should be exactly:
    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.

    1_Copy_Private_Repository_URL_from_the_GitHub_website
    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:

    1. Run,

      git status
      

      to check the status of your file. You will observe that state is modified.

    2. Now run,

      git add lab2_q2.sh
      

      to stage the modified file in the directory.

    3. Run

      git status
      

      again, to verify whether the file is staged.

    4. Run

      git commit -m "type message for your commit here"
      

      to commit the file which is staged.

    5. Run

      git status
      

      to verify that your working tree is clean.

    6. 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.

    2_Successful_attempt_to_clear_all_the_test_cases
    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.

    3_Reviewing_the_result_of_each_commit_on_GitHub
    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



ALL THE BEST
When you see a door with push sign, pull first to avoid conflicts!