小编bas*_*lab的帖子

列出 shell 脚本使用的所有程序

我试图找出一种方法来列出脚本在运行时将使用的所有程序,而无需实际运行它。

我写了这些快速而肮脏的单行:

# fill an array with all the useful words except variables, options, brackets, quotes
readarray -t list <<<$( grep -v '^#' script.sh | sed 's/[0-9a-zA-Z_\-]*=//g ; s/\${.*}//g ; s/\$(//g ; s/[)'\"\'\`']//g ; s/ --*.//g ' )

# for every word in array show info with `type' and clean the output again
for p in "${list[@]}" ; do type "${p}" ; done 2>&1 | grep -v -e '^bash:' -e 'shell keyword' -e 'shell builtin' | sort | uniq | …
Run Code Online (Sandbox Code Playgroud)

shell bash audit

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

标签 统计

audit ×1

bash ×1

shell ×1