bash - 如何从 PATH 中具有相同名称的脚本调用 bash 函数
问题描述
我在 PATH 中有一个名为 foo 的 bash 脚本
该脚本如下所示:
#!/usr/bin/env bash
foo_type=`type foo`;
if [[ -z "$foo_type" ]]; then
. "$HOME/.foo/shell.sh"
fi
'foo' "$@" ### this calls this script not the bash function in shell.sh
正如评论所暗示的问题是'foo'没有调用源bash函数,它最终调用了相同的脚本,所以我进入了一个无限循环,我得到了这个错误:
/.../bin/foo: fork: Resource temporarily unavailable
有谁知道如何调用 source bash 函数?
解决方案
如果定义了 bash 函数,这就是已经发生的事情。
您的脚本中的问题是foo_type
包含类似foo is /.../bin/foo
which 不为空的内容,因此该脚本永远不会被获取,并且永远不会定义函数。
您可以使用它set -x
来调试此问题和其他问题。
推荐阅读
- php - 无法在远程呈现中用 php 替换 pod
- c++ - 从文件中输出 ANSI 转义码的问题 (C++)
- google-apps-script - 如何根据 Google Apps 脚本中的当前月份生成一个月中的天数
- mysql - 计算与 2 个日期的天差
- mysql - 分组不计算数量和价格吗?
- reactjs - 道具的默认值
- oracle - 它一直在说“必须声明标识符'COUNTRY_NAME'”,当它已经是?
- invisible - 处理隐形代码以及如何取回它
- scala - 如何用 circe 定义一些通用解码器/编码器?
- javascript - 将 React 网页部署到 Github