Shell nesting variable "type $ (($num 1 + $num 2)"-1

Source: Internet
Author: User


[[email protected] shell-test] # chmod a + x para.sh
[[email protected] shell-test] # ll
total 44
-rw-r--r-- 1 root root 0 Jul 14 00:52 012
-rw-r--r-- 1 root root 201 Jul 14 19:04 2
-rw-r--r-- 1 root root 0 Jul 14 00:45 abc
-rwxr-xr-x 1 root root 149 Jul 14 03:24 echoTest1.sh
-rwxr-xr-x 1 root root 149 Jul 14 03:15 echoTest.sh
-rwxr-xr-x 1 root root 164 Jul 13 23:25 hello.sh
-rwxr-xr-x 1 root root 157 Jul 14 00:28 h.tx
-rwxr-xr-x 1 root root 201 Jul 14 19:04 para.sh
drwxr-xr-x 2 root root 4096 Jul 14 00:01 test
-rwxr-xr-x 1 root root 118 Jul 14 02:52 test1.sh
-rwxr-xr-x 1 root root 93 Jul 14 02:37 test $ .sh
-rw-r--r-- 1 root root 7283 Jul 14 02:20 vari.txt
[[email protected] shell-test] # sh para.sh as d f g 56 78
A total of 6 parameters
The parameters is: as d f g 56 78
The parameters is: as d f g 56 78
[[email protected] shell-test] # cat para.sh
#! / bin / bash
echo "A total of $ # parameters"
# 用 $ # represents the number of all parameters
echo "The parameters is: $ *"
#Use $ * for all parameters
echo "The parameters is: [email protected]"
#Using [email protected] also represents all parameters
[[email protected] shell-test] # sh test1.sh as d f g 56 78
0
[[email protected] shell-test] # sh test $ .sh as d f g 56 78
0
[[email protected] shell-test] # cat echoTest.sh
#! / bin / bash

for i in "$ *"
All parameters in # $ * are considered as a whole, so this for loop will only loop once
do
echo "The parameters is: $ i"
done
[[email protected] shell-test] # sh echoTest.sh as d f g 56 78
The parameters is: as d f g 56 78
[[email protected] shell-test] # sh echoTest1.sh as d f g 56 78
The parameters is: as
The parameters is: d
The parameters is: f
The parameters is: g
The parameters is: 56
The parameters is: 78
[[email protected] shell-test] # cat echoTest1.sh
#! / bin / bash

for i in "[email protected]"
All parameters in # $ * are considered as a whole, so this for loop will only loop once
do
echo "The parameters is: $ i"
done
[[email protected] shell-test] # cat echoTest1.sh
#! / bin / bash

for i in "[email protected]"
All parameters in # $ * are considered as a whole, so this for loop will only loop once
do
echo "The parameters is: $ i"
done
[[email protected] shell-test] # vim echoTest1.sh
[[email protected] shell-test] # sh echoTest1.sh as d f g 56 78
iThe parameters is: as
iThe parameters is: d
iThe parameters is: f
iThe parameters is: g
iThe parameters is: 56
iThe parameters is: 78
[[email protected] shell-test] # vim echoTest1.sh
[[email protected] shell-test] # sh echoTest1.sh as d f g 56 78
The parameters is: as
The parameters is: d
The parameters is: f
The parameters is: g
The parameters is: 56
The parameters is: 78
[[email protected] shell-test] # cat echoTest1.sh
#! / bin / bash

for i in "[email protected]"
Each parameter in # [email protected] is considered independent, so if there are several parameters in "[email protected]", it will loop several times
do
echo "The parameters is: $ i"
done
[[email protected] shell-test] # cp echoTest1.sh echoTest2.sh
[[email protected] shell-test] # vim echoTest2.sh
[[email protected] shell-test] # sh echoTest2.sh as d f g 56 78
x = 2The parameters is: as
x = 2The parameters is: d
x = 2The parameters is: f
x = 2The parameters is: g
x = 2The parameters is: 56
x = 2The parameters is: 78
[[email protected] shell-test] # cat echoTest2.sh
#! / bin / bash
x = 1
for i in "[email protected]"
Each parameter in # [email protected] is considered independent, so if there are several parameters in "[email protected]", it will loop several times
do
echo x = $ (($ x +1)) "The parameters is: $ i"
done
[[email protected] shell-test] # vim echoTest2.sh
[[email protected] shell-test] # sh echoTest2.sh as d f g 56 78
1 = 2The parameters is: as
1 = 2The parameters is: d
1 = 2The parameters is: f
1 = 2The parameters is: g
1 = 2The parameters is: 56
1 = 2The parameters is: 78
[[email protected] shell-test] # cat echoTest2.sh
#! / bin / bash
x = 1
for i in "[email protected]"
Each parameter in # [email protected] is considered independent, so if there are several parameters in "[email protected]", it will loop several times
do
echo "$ x = $ (($ x +1)) The parameters is: $ i"
done
[[email protected] shell-test] # vim echoTest2.sh
[[email protected] shell-test] # sh echoTest2.sh as d f g 56 78
1 The parameters is: as
2 The parameters is: d
3 The parameters is: f
4 The parameters is: g
5 The parameters is: 56
6 The parameters is: 78
[[email protected] shell-test] # cat echoTest2.sh
#! / bin / bash
x = 1
for i in "[email protected]"
Each parameter in # [email protected] is considered independent, so if there are several parameters in "[email protected]", it will loop several times
do
echo "$ x The parameters is: $ i"
x = $ (($ x +1))
done
[[email protected] shell-test] # vim echoTest2.sh
[[email protected] shell-test] # sh echoTest2.sh as d f g 56 78
1 The parameters is: as
2 The parameters is: d
3 The parameters is: f
4 The parameters is: g
5 The parameters is: 56
6 The parameters is: 78
[[email protected] shell-test] # cat echoTest2.sh
#! / bin / bash
x = 1
for i in "[email protected]"
Each parameter in # [email protected] is considered independent, so if there are several parameters in "[email protected]", it will loop several times
do
echo $ x The parameters is: $ i
x = $ (($ x +1))
done
[[email protected] shell-test] # vim echoTest2.sh
[[email protected] shell-test] # sh echoTest2.sh as d f g 56 78
The parameters 1 is: as
The parameters 2 is: d
The parameters 3 is: f
The parameters 4 is: g
The parameters 5 is: 56
The parameters 6 is: 78
[[email protected] shell-test] # cat echoTest2.sh
#! / bin / bash
x = 1
for i in "[email protected]"
Each parameter in # [email protected] is considered independent, so if there are several parameters in "[email protected]", it will loop several times
do
echo The parameters $ x is: $ i
x = $ (($ x
+1))
done
[[email protected] shell-test] # ll
total 48
-rw-r--r-- 1 root root 0 Jul 14 00:52 012
-rw-r--r-- 1 root root 201 Jul 14 19:04 2
-rw-r--r-- 1 root root 0 Jul 14 00:45 abc
-rwxr-xr-x 1 root root 163 Jul 14 19:16 echoTest1.sh
-rwxr-xr-x 1 root root 183 Jul 14 19:24 echoTest2.sh
-rwxr-xr-x 1 root root 149 Jul 14 03:15 echoTest.sh
-rwxr-xr-x 1 root root 164 Jul 13 23:25 hello.sh
-rwxr-xr-x 1 root root 157 Jul 14 00:28 h.tx
-rwxr-xr-x 1 root root 201 Jul 14 19:04 para.sh
drwxr-xr-x 2 root root 4096 Jul 14 00:01 test
-rwxr-xr-x 1 root root 118 Jul 14 02:52 test1.sh
-rwxr-xr-x 1 root root 93 Jul 14 02:37 test $ .sh
-rw-r--r-- 1 root root 7283 Jul 14 02:20 vari.txt
[[email protected] shell-test] # cat h.tx
world
#! / bin / Bash
#The first program
# Author: shenchao (E-mail: [email protected])
echo -e "Mr. Shen Chao is the most honest man in LampBrother"
[[email protected] shell-test] # cat test1.sh
#! / bin / bash
num1 = $ 1
num2 = $ 2
#sum = $ (($ num1 + $ num2))
sum = $ (($ num1 + $ num2))
#Variable sum is num1 plus num2
echo $ sum
[[email protected] shell-test] # mv test1.sh sum.sh
[[email protected] shell-test] # ll
total 48
-rw-r--r-- 1 root root 0 Jul 14 00:52 012
-rw-r--r-- 1 root root 201 Jul 14 19:04 2
-rw-r--r-- 1 root root 0 Jul 14 00:45 abc
-rwxr-xr-x 1 root root 163 Jul 14 19:16 echoTest1.sh
-rwxr-xr-x 1 root root 183 Jul 14 19:24 echoTest2.sh
-rwxr-xr-x 1 root root 149 Jul 14 03:15 echoTest.sh
-rwxr-xr-x 1 root root 164 Jul 13 23:25 hello.sh
-rwxr-xr-x 1 root root 157 Jul 14 00:28 h.tx
-rwxr-xr-x 1 root root 201 Jul 14 19:04 para.sh
-rwxr-xr-x 1 root root 118 Jul 14 02:52 sum.sh
drwxr-xr-x 2 root root 4096 Jul 14 00:01 test
-rwxr-xr-x 1 root root 93 Jul 14 02:37 test $ .sh
-rw-r--r-- 1 root root 7283 Jul 14 02:20 vari.txt
[[email protected] shell-test] # sh sum.sh 23 56
79
[[email protected] shell-test] # cat sum.sh
#! / bin / bash
num1 = $ 1
num2 = $ 2
#sum = $ (($ num1 + $ num2))
sum = $ (($ num1 + $ num2))
#Variable sum is num1 plus num2
echo $ sum
[[email protected] shell-test] # 


Shell nesting variable "type $ (($num 1 + $num 2)"-1


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.