Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retrieve all tools used in shell script

Tags:

linux

shell

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.

like image 439
deimus Avatar asked Sep 26 '11 12:09

deimus


3 Answers

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
like image 85
glenn jackman Avatar answered Oct 16 '22 15:10

glenn jackman


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.

like image 24
ks1322 Avatar answered Oct 16 '22 15:10

ks1322


While I have no general solution, you could try two approaches:

  1. You might use strace to see which programs were executed by your script.
  2. You might run your program in a pbuilder environment and see which packages are missing.
like image 1
thiton Avatar answered Oct 16 '22 16:10

thiton