Homework Help.

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

  1. The problem statement, all variables and given/known data:
    Hello,

My name is Jordan and studying at the New Bulgarian University in Sofiya. This is my homework but can not write the last two questions.

  1. Why command exit, placed in a shell script follows:
    (statements; exit)
    will not finish the script? How do you overcome it.

  2. Write a script that calculates the factorial of the number receiving
    as an argument. Suggest variant control arguments.

  3. Relevant commands, code, scripts, algorithms:

  4. The attempts at a solution (include all code and scripts):

  5. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):

New Bulgarian University, Sofiya. Teacher is N. Gadjev. Faculty number F49086

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).

The brackets cause the two commands to be executed in a subshell. Therefore the "exit" will only exit the subshell not the calling shell.

We need to tell the calling program that we want to exit. One way is to exit with a non-zero status and test that value in the calling script.

(statements; exit 2) ; REPLY=$?
if [ $REPLY -eq 2 ]
then
     exit
fi

simple factorial script:

#! /bin/ksh
n=$1
i=0
fact=1
while ((i<n)) ; do
        ((i=i+1))
        ((fact=fact*i))
done
echo $fact
exit 0