【问题标题】:Calling bash functions from sub process从子进程调用 bash 函数
【发布时间】:2011-03-25 15:33:50
【问题描述】:

我不确定它是否可能,但我正在寻找一种从其子进程中调用 bash 函数的方法。可能是这样的:

function testfunc() { echo test function; }
bash -c 'testfunc'

这显然不起作用,但是有什么方法可以实现这样的目标吗?

非常感谢您的帮助!

【问题讨论】:

标签: bash subprocess


【解决方案1】:
$ function blargh () {
> echo $1
> }
$ export -f blargh
$ bash
$ blargh hi there
hi
$ exit
$ bash -c "blargh hi there"
hi

export -f 是不明显的位。

$ help export
export: export [-fn] [name[=value] ...] or export -p
    Set export attribute for shell variables.

    Marks each NAME for automatic export to the environment of subsequently
    executed commands.  If VALUE is supplied, assign VALUE before exporting.

    Options:
      -f    refer to shell functions
    ...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-21
    • 2020-08-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多