Making a bash script and small C program for a homework assignment

Here's the assignment. I'll bold the parts that are rough for me. Unfortunately, that's quite a bit lol. The syntax is, of course, where my issues lie, for the most part. I don't have a lot of programming experience at all :/. I'd post what I've already done, but I'm so lost I really don't know where to start.

  • Login to your account on our Unix server
  • Type bash <enter>
  • You should have a directory named cs371 inside your home directory (from Assignment 1). Change into the cs371 directory. You are now in a directory which I will refer to as /home/me/cs371, where me is your login name.
  • Inside this /home/me/cs371 directory, create a subdirectory named assn7. (There should be an assn1 subdirectory from Assignment 1. We won't need that right now, though.)
  • Inside the current /home/me/cs371/assn7 directory, place the script a7.sh and the C program a7.c that you will write, which are described below. Make sure to set the permissions to 700 on your script so that you can run your script.
  • After you have put your completed a7.sh script and a7.c C program in the /home/me/cs371/assn7 directory, type
    script myOutput7.out <enter>. Then, type pwd <enter>. Then, type date <enter>.
    Then, using the cc C compiler on uxb3 with option -o, compile your a7.c program to make an executable named a7.out. Then run your a7.out executable file. Then, type exit <enter>.

The a7.sh script:
Create a script named a7.sh using the vim editor that can be run in a bash shell.

  • The first line of your script should be the she-bang line. It should specify that a bash sub-shell be created for running the script.
  • Your script should be documented properly with comments, which begin with the pound symbol #. At the top of your script file (below the she-bang line), you should have a comment with your name, the assignment number and the date. Next to each command you should have a comment explaining what the command does.
  • Your a7.sh script should contain a function distinctNos that uses three parameters. All three parameters should be integers. The function is a "success" (with exit status 0) if there are exactly three parameters and they are distinct numbers. The function should have an exit status of 1 if there are three parameters but they are not all distinct numbers. The function should should have an exit status of 2 if there are fewer or more than 3 parameters.
  • Also, in a7.sh, you should call your function distinctNos with three parameters 55 -3 12
  • Also, in a7.sh, you should print an appropriate message to the standard output after calling distinctNos with parameters 55 -3 12 to say whether or not there were three parameters and whether or not they were distinct numbers. Use an if conditional and the exit status on your function call to do this. This if conditional may not be in the function distinctNos. (Your code should work if I were to change the parameters used on your function call.)

The a7.c C program:
Create a C program named a7.c using the vim editor that can be compiled using cc and executed on uxb3.wiu.edu.

  • Your program should be documented properly with comments. At the top of your file you should have a comment with your name and the assignment number. Next to each command you should have a comment explaining what the command does. You must also use proper indentation.
  • Your a7.c program should use printf to print a nice message. (You can decide what to say.) Then the process should use the fork system call to create a child process. Then, your code should do different things depending on whether the process is the parent or the child:
    [list]
  • The parent should print one more message (using printf) saying that it is the parent, what its PID is, and what its child's PID is. It should then contain the command sleep(9);
  • The child process should use the execl system call to load and run your a7.sh script.

    [/list]

Anyways, if someone could help me out, I'd be very thankful :slight_smile:

Do not post classroom or homework problems in the main forums. Homework and coursework questions can only be posted in this forum under special homework rules.

Please review the rules, which you agreed to when you registered, if you have not already done so.

More-than-likely, posting homework in the main forums has resulting in a forum infraction. If you did not post homework, please explain the company you work for and the nature of the problem you are working on.

If you did post homework in the main forums, please review the guidelines for posting homework and repost.

Thank You.

The UNIX and Linux Forums.