Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux how to find all executables in a script

I am writing some bash scripts that I want to deliver and mantain with a deb package. As I need to list the dependencies of the package, I would like to find all executables that the scripts are calling and find which packages do they belong.

Is it possible to list all executables called by a bash script?

EDIT

To better clarify: say that my script is

#!/bin/sh
echo "hello"
cat file.txt | grep -v "STRING"
if [ -d $SOMEDIR ]; then
    ./something.sh
else
    ./something_else.sh
fi

I would like to analyze the content of such script and the output should be:

echo
cat
grep
./something.sh
./something_else.sh

(regardless of any other possible executable called by the other two *.sh scripts)

like image 593
alephz3r0 Avatar asked Nov 20 '25 19:11

alephz3r0


1 Answers

You can run your scripts through strace and check the executables invoked

$ strace -qqfe execve ./script.sh

and you'll get something like

execve("./script.sh", ["./script.sh"], [/* 81 vars */]) = 0
[pid 27651] execve("/bin/grep", ["grep", "hello"], [/* 80 vars */]) = 0
...
like image 149
Diego Torres Milano Avatar answered Nov 23 '25 10:11

Diego Torres Milano