1.4-shell Custom Variables

Source: Internet
Author: User

During script execution, if there are some commands or paths that are long and need to be used repeatedly. Variables are used instead, which makes it easy to change and maintain.

Read-t3-p "Please input a number:" N

Echo $n

Read is commonly used to implement human-computer interaction , and assigns the input value to the variable n -t3 specified time-out, more than 3 seconds, and returns to the system prompt.

Built-in variables in the shell: $ $1-$9 $ #等

Vim test.sh

Example: Echo "\$0=$0"

echo "\$1=$1"

echo "\$2=$2"

echo "\$#=$#"

To show $1=? Format, the default is $1-$9 null. where $ A defaults to the file name, $ #为所有参数的个数

Execute bash test.sh AA 2c will be assigned to $ $ and 2c respectively

Variables for mathematical operations:

A=1;b=2;c= $a + $b; Echo $c result is 1+2, no mathematical operation

a=1;b=2;c=$[$a + $b]; Echo $c result is 3, which is a fixed notation for mathematical operations []


1.4-shell Custom Variables

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.