I'm not sure if its possible, but I'm looking for a way to call a bash function from its subprocess. It could be something like:
function testfunc() { echo test function; }
bash -c 'testfunc'
This doesn't work obviously, but is there any way to achieve something like this?
Thanks a lot for the help!
$ function blargh () {
> echo $1
> }
$ export -f blargh
$ bash
$ blargh hi there
hi
$ exit
$ bash -c "blargh hi there"
hi
export -f is the non-obvious bit.
$ 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
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With