【问题标题】:Is there a way to source bash script inside other sourced script有没有办法在其他源脚本中获取 bash 脚本
【发布时间】:2016-03-18 21:28:11
【问题描述】:

我的问题如下: 我有我的库(我们称之为qa-baslib.sh),其中包含各种实用功能,我正在包含它测试脚本,我们正在开发。

现在,其他开发人员创建了 bash 脚本库来支持与各种服务器的 SSH 连接(我们称之为global_ssh)。它看起来像:

global_ssh:

#!/bin/bash

global_ssh(){

   # Doing some ssh stuff
}

我正在采购这样的 global-ssh 文件:

qa-baslib.sh

#!/bin/bash

 . /<path-to>/qa-util-scripts/global_ssh

function some_util_function() {
   server=$1
   command=$2

   # Here i'm calling global_ssh function
   timeout -s 9 30 global_ssh $sever $command
}

但是当我最终执行该函数时,通过从命令行获取它,我得到了错误:

]# . /<path-to>/qa-bashlib.sh
]# some_util_function $server $command
]# timeout: failed to run command `global_ssh': No such file or directory

出了什么问题,有什么解决办法吗?

谢谢

【问题讨论】:

  • 脚本 #1 中的 shebang 是错字还是原因?
  • @frlan 抱歉,已修复 :)
  • 你确定你系统的timeout可以运行shell函数吗? (type timeout 打印什么?)编辑添加:参见stackoverflow.com/questions/9954794/…
  • @ruakh /sbin/timeout。谢谢大佬,说的很对!以前只有ssh 所以timeout -s 9 30 ssh 是有效的,但是当我用函数替换ssh 时,我也应该删除超时:)

标签: linux bash


【解决方案1】:

正如@ruakh 提到的,timeout 不能以 bash 函数作为参数运行。

完整答案: execute function with timeout

【讨论】:

    猜你喜欢
    • 2020-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多