我试图找出一种方法来列出脚本在运行时将使用的所有程序,而无需实际运行它。
我写了这些快速而肮脏的单行:
# 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)