【问题标题】:Passing variables in arguments在参数中传递变量
【发布时间】:2012-06-08 14:11:39
【问题描述】:

我正在寻找如何在查找文件函数中传递参数 这应该首先为我的计算机中的所有 sh 文件提供 basename 一个选项卡,然后是所有 目录 例如myBashfile.sh *sh 目前我有这个: 而 getopts b opt 做 案例$选择加入 b) find / -name $OPTARG -printf "%f\n"-print 2>/dev/null ;; 经社理事会 完毕 至尊只给出 测试1.sh 测试60.sh 另一个test.sh

但我需要作为输出:(带有标签) test1.sh /home/directory5/directory6 test60.sh /home/directory50/directory6 anothertest.sh /home/directory5/directory6

谁能帮帮我?

【问题讨论】:

  • 你试过什么?你应该阅读这个:meta.stackexchange.com/a/128553
  • 切线地,shell 将尝试扩展*sh,方法是在传递给脚本之前查看当前目录。以myBashfile.sh "*sh" 开头,这样您的脚本才能真正看到星号。

标签: bash find filenames arguments


【解决方案1】:

综合answermanuals。简而言之:

$1 # means the 1st argument
$2 # means the 2nd argument
$@ # means all arguments

【讨论】:

    猜你喜欢
    • 2018-10-28
    • 2011-07-27
    • 2016-06-02
    • 2015-12-20
    • 1970-01-01
    • 2012-04-12
    • 1970-01-01
    • 2010-09-17
    相关资源
    最近更新 更多