Shell script that calculates the factorial of n by a shell program.

Source: Internet
Author: User

[Email protected] ~]#CatJiechen.SH #!/bin/bash# Design a shell program to calculate the factorial of N, required: #1. Receive parameters from the command line n;#2to determine the legality of n immediately after the commencement of the program, that is, whether there are parameters, if any, if there is a positive integer, if illegal, please give the wrong hint. #3. The result of the final calculation
Num=$1Expr$num +1&>/dev/NULL[ $? -ne0] &&Echo "Please input a number."&& exit2[ $# -ne1] &&Echo 'usage:$0 Number'&& exit1[$num-le0] &&Echo "Please input a number bigger than 0"&& exit3s=1 forIinch`seq 1$num ' Dos=$ (($s *$i)) DoneEcho$s [[email protected]~]# bash Jiechen.SH 5 -[[Email protected]~]# bash Jiechen.SH 36[[Email protected]~]# bash Jiechen.SH 22[[Email protected]~]# bash Jiechen.SH 11[[Email protected]~]#

Shell script that calculates the factorial of n by a shell program.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.