首页 > 系统相关 >shell传参内容超过10个如何获取

shell传参内容超过10个如何获取

时间:2022-11-02 17:33:12浏览次数:39  
标签:传参 10 shell sh test root localhost

编写脚本中 如果我们命令行传参个数超过10个,无法获取第九个以后的值

测试:(可以看到,从第10个传参开始,无法获取正确传参内容)

[root@localhost ]# cat test.sh
#!/bin/bash

test1=$1
test2=$2
test3=$3
test4=$4
test5=$5
test6=$6
test7=$7
test8=$8
test9=$9
test10=$10
test11=$11

echo $test1 $test2 $test3 $test4 $test5 $test6 $test7 $test8 $test9 $test10 $test11
[root@localhost ]# sh test.sh 1 2 3 4 5 6 7 8 9 a b
1 2 3 4 5 6 7 8 9 10 11
[root@localhost ]# sh test.sh 1 2 3 4 5 6 7 8 a b c
1 2 3 4 5 6 7 8 a 10 11
遇到这种情况,我们只需要在shell中用 {} 括起来,如下:

[root@localhost ]# cat test.sh
#!/bin/bash

test1=$1
test2=$2
test3=$3
test4=$4
test5=$5
test6=$6
test7=$7
test8=$8
test9=$9
test10=${10}
test11=${11}

echo $test1 $test2 $test3 $test4 $test5 $test6 $test7 $test8 $test9 $test10 $test11
[root@localhost ]# sh test.sh 1 2 3 4 5 6 7 8 9 a b
1 2 3 4 5 6 7 8 9 a b
[root@localhost ]# sh test.sh 1 2 3 4 5 6 7 8 a b c
1 2 3 4 5 6 7 8 a b c

标签:传参,10,shell,sh,test,root,localhost
From: https://www.cnblogs.com/xiongty/p/16851778.html

相关文章

  • shell语法
    shell语法1摘自:https://www.acwing.com/file_system/file/content/whole/index/content/2855883/概论shell是我们通过命令行与操作系统沟通的语言。shell脚本可以直接......
  • vue demo 1102
    <scriptlang="ts">import{ref,defineComponent}from'vue'exportdefaultdefineComponent({setup(){constfields=['name','address','email'......
  • qt错误?undefinedreferenceto`_imp___ZN10QTcpSocketD1Ev
    错误信息:undefinedreferenceto`_imp___ZN10QTcpSocketD1Ev'undefinedreferenceto`_imp___ZN10QTcpSocketC1EP7QObject'undefinedreferenceto`_imp___ZN10QTcpSo......
  • 巧用shell脚本批量替换字符串
    ​作者:田逸(formyz)需求描述​有一个网站,因为域名变更,除了需要重新做域名解析外,还需要对网站目录的包含原域名的文件进行替换。包含域名(主机名)关键字的文件相当的多,它们分布在......
  • leetcode110-平衡二叉树
    110.平衡二叉树这道题很容易联想到 104.二叉树的最大深度 的做法。一开始做的时候就知道可以用递归,但是又想到了左右子树的高度相差不大于1,但是子树的子树相差大于1......
  • WordPress零基础建站教程:搭建本地数据库 1/10
    网页作为互联网内容的基本组成,承担了互联网几乎所有的内容展示功能,在我们点击一个链接时,几乎都是将我们转入一个网页显示界面,而我们也是通过这些形式各异的网页,打开了万紫千......
  • WordPress零基础建站教程:内网穿透将本地web站点发布到公网 5/10
    在前面的文章中,我们已经向大家介绍了如何搭建一个属于自己的网页,虽然这个网页还没有添加内容,但确实已经有了网页的基本框架,等着我们用创意和需求去填满它。为了我们的网页能......
  • 树莓派搭建WordPress博客:为网站配置固定的URL地址 3/10
    在上篇文章中,我们向大家介绍了使用cpolar创建一个临时数据隧道,让本地树莓派的网页能被公网访客访问到的方法,但由于此时的cpolar还没有进行更高级的配置,因此该数据隧道会在cp......
  • WordPress零基础建站教程:配置本地数据库 2/10
    在​​上一篇文章​​中,我们介绍了如何在localhost中建立一个数据库,但此时的数据库还不能起到什么作用,因此我们需要对其进行进一步设置。而设置该数据库的第一步,就是设定用......
  • 人工智能环境搭建-ubantu python3.10.8安装记录
    当前时间(2022-11)python3.11已经出来,python3.10已稳定 配置一个AI开发的python环境,代码部署迁移时,安装环境也一块带走OS:ubantu20.10安装用户:xt,  python环境sqlite......