Introduction to shell-related directives

Source: Internet
Author: User

$#, the number of arguments followed by the script runtime
#! /bin/bash

Case ' $# ' in
0) printf "Enter A number: "
Read
n= $REPLY
;;
*) n=$1
;;
Esac
X=$ (((1 + $n) * $n/2))
echo "Tne value of 1 + 2 + 3....+ $n = $x"
The meaning of this shell:
If the number of arguments is zero, you are prompted to enter a number;
If the number of arguments is nonzero, the value of the first parameter is taken
Then calculate the value of 1 to this number, output!

Echo >> is append, echo > is overlay


$* and [email protected] and $ #的区别
For example,
The script name is called test.sh Three: 1 2 3
After running test.sh 1 2 3
$* is "1 2 3" (enclosed in quotation marks)
[Email protected] is "1" "2" "3" (separately wrapped)
$ #为3 (number of parameters)

Introduction to shell-related directives

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.