我试图找出一种方法来列出脚本在运行时将使用的所有程序,而无需实际运行它。
我写了这些快速而肮脏的单行:
# 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 | sed 's/^.* //g ; s/[\(\)]//g'
Run Code Online (Sandbox Code Playgroud)
我认为存在的问题是:
有什么更好的解决办法吗?
在线程https://www.unix.com/shell-programming-and-scripting/268856-how-pre-check-scrutinize-all-my-shell-scripts.html的帖子 #16 中,我发布了 150 行 perl脚本p1.txt这可能是一个有用的起点。我还添加了一个指向更完整、更复杂的 shell 解析器的链接
最好查看整个线程——也许其他一些观点也可能令人感兴趣。
最美好的祝愿...干杯,drl
| 归档时间: |
|
| 查看次数: |
1835 次 |
| 最近记录: |