LINUX 脚本退出及参数迁移

浅谈在Linux中如何给shell脚本传参数

这里我们用到位置参数变量。

位置参数变量:

执行脚本时获取命令参数信息。

即:向脚本中传递数据。

常用的位置参数变量列举:

$n:

n为自然数。

0代表命令本身,1-9代表第1-9个参数

注意:10以上的参数要用大括号,如:${17}。

$*:

代表命令行中所有的参数(不包括$0)。for循环遍历时,只会循环一次。

$@:

代表命令行中所有的参数(不包括$0),for循环遍历时,可循环多次。

$#:

代表命令行中所有参数的个数(不包括$0)。

案例:

创建一个脚本location.sh

vi location.sh

输入如下

#!bin/bash

#测试给给shell脚本传参数

#author:odysee

echo “参数列表:”

for x in “$*”

do

echo $x

done

echo “程序名:$0”

echo “参数个数:$#”

//在脚本后面输入参数1 2 3 4 5 6 7,传递给脚本location.sh

[odysee@kingdom shellFiles]$ bash location.sh 1 2 3 4 5 6 7

//打印所有传入的参数,遍历$@/$*

参数列表:

1 2 3 4 5 6 7

//打印程序名,$0

程序名:location.sh

//打印参数的总个数,$#

参数个数:7

测试完成

好了到这就结束了,感谢观看!

此文章来自固定链接:http://www.rakbuluo.com/p46

原文链接:,转发请注明来源!

发表评论

  • 8 Responses to “LINUX 脚本退出及参数迁移”
    • viagra canadian pharmacy ycnikm

      pharmacy rx one 60 mg cialis <a href="http://edpharmacystore.com/">Get More Info</a> canadian pharmacy store
      <a href=http://edpharmacystore.com/>his explanation</a>

      回复
    • viagra use patdjw

      online canadian pharcharmy <a href="http://edpharmacystore.com/">learn here</a> canadian pharmacies viagra
      <a href=http://edpharmacystore.com/>click here for info</a>

      回复
    • walmart medication list acjvgx

      canadian-drugs <a href=http://www.canada1drugstore.com/tadalafil/>www.northwestpharmacy.com</a> generic cialis in canada
      <a href="http://www.canada1drugstore.com/tadalafil/">viagra online purchase</a> cialis brand

      回复
    • Charlesedity

      viamedic.com <a href="http://fluencyuniversity.com/members/perez11povlsen/activity/497914/">viagra canada pharmacy</a> canada drugstore <a href=http://schmelkes.com/wiki/index.php?title=Acid_Reflux_Advice_That_Anyone_Can_Use>ed treatment medications</a> viagra sales
      cialis <a href="http://xabez.ru/user/BeasleyHorowitz1/">generic viagra 100mg</a> viagra plus <a href=http://forum.2serveothers.com/member.php?action=profile&uid=70133>prescription drugs from canada prices</a> cialis generic canada
      buy viagra online without a prescription <a href="https://www.openstreetmap.org/user/Flanagan%20Fogh">viagra cheapest</a> buy propecia <a href=http://www.sixfigureclassifieds.com/user/profile/121563>canada prescription</a> canada pharmacy online
      northwestpharmacy

      回复
    • does viagra work yuqoel

      substitute viagra <a href="https://firsturl.de/azxX612">cheap viagra india</a> viagra in canada <a href=http://paukpasyans.ru/user/JuhlDuus0/>no prescription viagra</a> cvs pharmacy
      canada pharmacies online <a href="https://devpost.com/cliffordlindgren262498">cheap generic viagra online</a> hypnosis orgasm <a href=https://netcshop.com/forum/user-timmermann77povlsen.html>cheapest price for cialis</a> drugstore of canada
      canadian pills online <a href="http://www.drhack.net/index.php?qa=user&qa_1=chaney29erickson">buy viagra without a prescription</a> discount rx drugs <a href=https://mybbplugins.com/member.php?action=profile&uid=175913>viagra</a> cialis without prescription
      natural substitute for viagra

      回复
    • canadian online pharmacy for viagra plvtdx

      cialis online canada <a href=http://www.canada1drugstore.com/tadalafil/>pharmacy viagra</a> india pharmacy viagra
      <a href="http://www.canada1drugstore.com/tadalafil/">viagra online canada</a> canadian meds viagra

      回复
    • melospnmcnml

      nwiegmqyt buy cialis in usa <a href=https://larsonharbo02.mystrikingly.com/>sundrugstore.com</a> is generic cialis safe buy medication without an rx <a href="https://britishrestaurantawards.org/members/larsonballard27/activity/371210/">cialis online with prescription</a>
      buy generic ed pills online <a href=https://www.pcb.its.dot.gov/PageRedirect.aspx?redirectedurl=https://barkertennant86.bravejournal.net/post/2020/10/23/Tips-On-How-To-Take-Care-Of-Your-Hair>cialis without a doctor's prescription in usa</a> sundrugstore.com cialis 100mg <a href="http://itshecto.com/home.php?mod=space&uid=199558">canada drug pharmacy</a>

      回复
    • Stephenpeaky

      viagra doses 200 mg <a href=" http://sild100fast.com/# ">viagra for sale</a> is there a generic for viagra

      回复