From: zy on
I would like to list all the external programs that will be possibly
executed by a given bash script.

Anyone knows a way to do this without messing with /bin/bash source
code?
From: Kenny McCormack on
In article <67749a7d-278e-404d-8d62-ef852474d6d9(a)l12g2000prg.googlegroups.com>,
zy <zyconf(a)gmail.com> wrote:
>I would like to list all the external programs that will be possibly
>executed by a given bash script.
>
>Anyone knows a way to do this without messing with /bin/bash source
>code?

find / -print

should do it. As you can see, the possibilities are (almost) endless.

From: OldSchool on
On Mar 5, 10:08 am, zy <zyc...(a)gmail.com> wrote:
> I would like to list all the external programs that will be possibly
> executed by a given bash script.
>
> Anyone knows a way to do this without messing with /bin/bash source
> code?

do you really mean "Given script xyz, I want to create a list of all
non-builtin commands existing in that script?"
From: Icarus Sparry on
On Fri, 05 Mar 2010 07:08:45 -0800, zy wrote:

> I would like to list all the external programs that will be possibly
> executed by a given bash script.
>
> Anyone knows a way to do this without messing with /bin/bash source
> code?

Not possible - unless you generate a list of every program on the machine.

Consider what programs can be run by

eval $(evil)

this will take the output of the "evil" program and will use it as the
command to run. Since you do not know all possible outputs of the "evil"
program in advance, you can not see all the things that might possibly be
executed.

You could get an approximate list by attempting to parse the shell input,
or even just doing pattern matching, so remove comments, remove strings
and other quoted things, remove keywords, join continued lines, get the
first word on each line or after a semicolon.

From: Jon LaBadie on
zy wrote:
> I would like to list all the external programs that will be possibly
> executed by a given bash script.
>
> Anyone knows a way to do this without messing with /bin/bash source
> code?

As others have pointed out, static analysis of the source code can not
give an answer to the question when you ask for "all ... possible".
Once an external program is executing, it can execute other programs
and nothing in your bash script will show that.

Perhaps your needs can be met by dynamic tracing. Most OSs provide
a program that will trace all system calls made by a program. Typically
you can also follow child processes as well. If you then filter out
just the fork/exec calls, that will show what executables are run.

However, be aware that the results will only show what programs are
run for that particular execution. With that set of input data,
command line options, user and system environment, date and time,
and anything else that might affect the flow through your script.