gpt4 book ai didi

function - 在 shell 中导出函数

转载 作者:行者123 更新时间:2023-12-03 05:07:21 25 4
gpt4 key购买 nike

请告诉我如何在父 shell(bash、sh 或 ksh)中导出函数,以便该函数可供从父进程启动的所有子进程使用?

最佳答案

export -f 功能特定于 Bash:

父级

#!/bin/bash
plus1 () { echo $(($1 + 1)); }
echo $(plus1 8)
export -f plus1
./child 14 21

child

#!/bin/bash
echo $(plus1 $(($1 * $2)) )

关于function - 在 shell 中导出函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1885871/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com