shell 嵌套 变量 【 型如 $(( $num1 + $num2)) 】 -1
来源:互联网 发布:北京尚学堂java学费 编辑:程序博客网 时间:2024/06/06 02:52
[root@cdh1 shell-test]# chmod a+x para.sh [root@cdh1 shell-test]# lltotal 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.shdrwxr-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[root@cdh1 shell-test]# sh para.sh as d f g 56 78A total of 6 parametersThe parameters is: as d f g 56 78The parameters is: as d f g 56 78[root@cdh1 shell-test]# cat para.sh#!/bin/bashecho "A total of $# parameters"#使用$#代表所有参数的个数echo "The parameters is: $*"#使用$*代表所有的参数echo "The parameters is: $@"#使用$@也代表所有参数[root@cdh1 shell-test]# sh test1.sh as d f g 56 780[root@cdh1 shell-test]# sh test$.sh as d f g 56 780[root@cdh1 shell-test]# cat echoTest.sh#!/bin/bashfor i in "$*"#$*中的所有参数看成是一个整体,所以这个for循环只会循环一次doecho "The parameters is: $i"done[root@cdh1 shell-test]# sh echoTest.sh as d f g 56 78The parameters is: as d f g 56 78[root@cdh1 shell-test]# sh echoTest1.sh as d f g 56 78The parameters is: asThe parameters is: dThe parameters is: fThe parameters is: gThe parameters is: 56The parameters is: 78[root@cdh1 shell-test]# cat echoTest1.sh#!/bin/bashfor i in "$@"#$*中的所有参数看成是一个整体,所以这个for循环只会循环一次doecho "The parameters is: $i"done[root@cdh1 shell-test]# cat echoTest1.sh#!/bin/bashfor i in "$@"#$*中的所有参数看成是一个整体,所以这个for循环只会循环一次doecho "The parameters is: $i"done[root@cdh1 shell-test]# vim echoTest1.sh[root@cdh1 shell-test]# sh echoTest1.sh as d f g 56 78iThe parameters is: asiThe parameters is: diThe parameters is: fiThe parameters is: giThe parameters is: 56iThe parameters is: 78[root@cdh1 shell-test]# vim echoTest1.sh[root@cdh1 shell-test]# sh echoTest1.sh as d f g 56 78The parameters is: asThe parameters is: dThe parameters is: fThe parameters is: gThe parameters is: 56The parameters is: 78[root@cdh1 shell-test]# cat echoTest1.sh#!/bin/bashfor i in "$@"#$@中的每个参数都看成是独立的,所以“$@”中有几个参数,就会循环几次doecho "The parameters is: $i"done[root@cdh1 shell-test]# cp echoTest1.sh echoTest2.sh [root@cdh1 shell-test]# vim echoTest2.sh[root@cdh1 shell-test]# sh echoTest2.sh as d f g 56 78x=2The parameters is: asx=2The parameters is: dx=2The parameters is: fx=2The parameters is: gx=2The parameters is: 56x=2The parameters is: 78[root@cdh1 shell-test]# cat echoTest2.sh#!/bin/bashx=1for i in "$@"#$@中的每个参数都看成是独立的,所以“$@”中有几个参数,就会循环几次doecho x=$(( $x +1 ))"The parameters is: $i"done[root@cdh1 shell-test]# vim echoTest2.sh[root@cdh1 shell-test]# sh echoTest2.sh as d f g 56 781=2The parameters is: as1=2The parameters is: d1=2The parameters is: f1=2The parameters is: g1=2The parameters is: 561=2The parameters is: 78[root@cdh1 shell-test]# cat echoTest2.sh#!/bin/bashx=1for i in "$@"#$@中的每个参数都看成是独立的,所以“$@”中有几个参数,就会循环几次doecho "$x=$(( $x +1 ))The parameters is: $i"done[root@cdh1 shell-test]# vim echoTest2.sh[root@cdh1 shell-test]# sh echoTest2.sh as d f g 56 781 The parameters is: as2 The parameters is: d3 The parameters is: f4 The parameters is: g5 The parameters is: 566 The parameters is: 78[root@cdh1 shell-test]# cat echoTest2.sh#!/bin/bashx=1for i in "$@"#$@中的每个参数都看成是独立的,所以“$@”中有几个参数,就会循环几次doecho "$x The parameters is: $i"x=$(( $x +1 ))done[root@cdh1 shell-test]# vim echoTest2.sh[root@cdh1 shell-test]# sh echoTest2.sh as d f g 56 781 The parameters is: as2 The parameters is: d3 The parameters is: f4 The parameters is: g5 The parameters is: 566 The parameters is: 78[root@cdh1 shell-test]# cat echoTest2.sh#!/bin/bashx=1for i in "$@"#$@中的每个参数都看成是独立的,所以“$@”中有几个参数,就会循环几次doecho $x The parameters is: $ix=$(( $x +1 ))done[root@cdh1 shell-test]# vim echoTest2.sh[root@cdh1 shell-test]# sh echoTest2.sh as d f g 56 78The parameters 1 is: asThe parameters 2 is: dThe parameters 3 is: fThe parameters 4 is: gThe parameters 5 is: 56The parameters 6 is: 78[root@cdh1 shell-test]# cat echoTest2.sh#!/bin/bashx=1for i in "$@"#$@中的每个参数都看成是独立的,所以“$@”中有几个参数,就会循环几次doecho The parameters $x is: $ix=$(( $x +1 ))done[root@cdh1 shell-test]# lltotal 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.shdrwxr-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[root@cdh1 shell-test]# cat h.tx world#!/bin/Bash#The first program# Author: shenchao (E-mail: shenchao@lampbrother.net)echo -e "Mr. Shen Chao is the most honest man in LampBrother"[root@cdh1 shell-test]# cat test1.sh #!/bin/bashnum1=$1num2=$2#sum=$(( $num1 + $num2))sum=$(( $num1 + $num2))#变量sum的和是num1加num2echo $sum[root@cdh1 shell-test]# mv test1.sh sum.sh[root@cdh1 shell-test]# lltotal 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.shdrwxr-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[root@cdh1 shell-test]# sh sum.sh 23 5679[root@cdh1 shell-test]# cat sum.sh #!/bin/bashnum1=$1num2=$2#sum=$(( $num1 + $num2))sum=$(( $num1 + $num2))#变量sum的和是num1加num2echo $sum[root@cdh1 shell-test]#
0 0
- shell 嵌套 变量 【 型如 $(( $num1 + $num2)) 】 -1
- java 矩阵相乘,arr1[num1][num2] * arr2[num2][num3]
- identifier of an instance ... altered from num1 to num2
- HDU 1406 注意输入判断num1 和 num2的大小
- shell变量嵌套
- 对三个整数排序,由键盘输入3个数存入num1,num2,num3,中使得结果为num1 <= num2 <= num3
- Swift函数参数 test(number1 num1:Int,number2 num2:Int),test(number1: 3, number2: 5)
- JavaSE: 关于 for&if 结合的经典例题:求num1-num2之间的素数
- shell 脚本之变量嵌套
- C语言基础 输入两个整数num1和num2,并根据运算符的不同进行不同的运算。
- 算法:Rev(X)函数为翻转数字 输入两个数 求他们的 result=Rev(Rev(num1)+Rev(num2))
- 华为上机-要求编程实现上述高精度的十进制加法。要求实现函数: void add (const char *num1, const char *num2, char *result)
- shell变量1
- shell变量-1
- Shell编程(1):变量
- num1 第一次
- 变量+shell变量(1)
- Shell变量功能(1)
- Errors running builder 'DeploymentBuilder' on project 'webdemo'.java.lang.NullPointerException
- Nginx开发从入门到精通
- JDBC使用反射读取properties文件方法笔记
- 正则表达式及API
- Discuz!X数据库函数操作命令(转载)
- shell 嵌套 变量 【 型如 $(( $num1 + $num2)) 】 -1
- 设计模式(四):单例模式Singleton(创建型模式)
- OO与设计模式第二次复习
- 对Rxjava1.0的map方法的源码分析
- blob类型的数据,可以保存图片,直接把图片转化为代码,和text不同,editkindor常用到
- DZY Loves Balls
- static类成员
- 使用 adb 命令一次性为多个设备安装 apk
- Caffe: MNIST 数据集格式转换、用 python 读写 LMDB 数据库