The shell implements a two number addition

Source: Internet
Author: User
Tags function definition

Write at the beginning, always write wrong, seemingly simple function, but must be careful; function definition:

Funciton functionname {...} There must be a space between functionname and {! I just did not add a space, has been an error.

Implement two number additions:

#! /usr/bin/kshfunction Add {    if (($# < 2  ));        then "the arg in ' t correct"    C7>else            sum=$ (($1+$2))        echo $sum    11 2

Or

#! /usr/bin/kshfunction Add {    if (($# < 2  ));        then "the arg in ' t correct"    C7>else            sum=$ (($1+$2))        echo $sum    fi}sum=$ (add 1) print $sumsum=$ (add 1 2) print $sum

The output of the two results is:

The arg in ' t correct
3

The shell implements a two number addition

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.