gpt4 book ai didi

linux - 如何检索 shell 脚本中使用的所有工具

转载 作者:IT王子 更新时间:2023-10-29 00:33:15 26 4
gpt4 key购买 nike

我有一堆使用一些命令和其他工具的 shell 脚本。

那么有没有一种方法可以列出 shell 脚本正在使用的所有程序?从源代码中检索依赖项的一种方式。

最佳答案

使用 sed 翻译管道和 $( 到换行符,然后使用 awk 输出一行的第一个单词,如果它可能是一个命令。管道进入 which 以在 PATH 中找到潜在的命令词:

sed 's/|\|\$(/\n/g' FILENAME | 
awk '$1~/^#/ {next} $1~/=/ {next} /^[[:space:]]*$/ {next} {print $1}' |
sort -u |
xargs which 2>/dev/null

关于linux - 如何检索 shell 脚本中使用的所有工具,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7555175/

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