小编Kyr*_*Kyr的帖子

如何在终端中打印 shell 函数的代码?

我正在使用zsh并且在一些 shell 脚本中定义了一些实用程序 shell 函数,其中很少有调用 from ~/.zshrc,所以假设我们不知道这些函数的位置。一个功能是:

function k.pstree.n {
    if [ "$1" != "" ]
    then
        pstree -p | grep -C3 "$1"
    else
        printf "  Please specify the name of the process you want to show!\n"
    fi
}
Run Code Online (Sandbox Code Playgroud)

如何打印该shell函数的代码?

我可以想到像这样的搜索和 grep:

find $(pwd) -name "*sh*" -type f -printf "\"%p\"\n" | xargs grep -C5 "k.pstree.n"
Run Code Online (Sandbox Code Playgroud)

但这假设我大致知道此处不正确的位置。

zsh function

7
推荐指数
1
解决办法
2345
查看次数

标签 统计

function ×1

zsh ×1