I've got bunch of shell scripts that used some command and other tools.
So is there a way I can list all programs that the shell scripts are using ? Kind of way to retrieve dependencies from the source code.
Uses sed
to translate pipes and $(
to newlines, then uses awk
to output the first word of a line if it might be a command. The pipes into which
to find potiential command words in the PATH:
sed 's/|\|\$(/\n/g' FILENAME |
awk '$1~/^#/ {next} $1~/=/ {next} /^[[:space:]]*$/ {next} {print $1}' |
sort -u |
xargs which 2>/dev/null
One way you can do it is at run time. You can run bash script in debug mode with -x
option and then parse it's output. All executed commands plus their arguments will be printed to standard output.
While I have no general solution, you could try two approaches:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With