From: Icarus Sparry on 6 Mar 2010 13:43 On Sat, 06 Mar 2010 19:30:49 +0100, Janis Papanagnou wrote: > Icarus Sparry wrote: >> On Fri, 05 Mar 2010 18:03:43 -0800, zy wrote: >> >>> On Mar 6, 1:36 am, Icarus Sparry <use...(a)icarus.freeuk.com> wrote: >>>> 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? [even more problems listed] > I think the best approach would be to overlay the exec calls by an own > function that logs the function prior to exec'ing. My *guess* is that the OP wants to create a list of programs that need to be installed, so unless he has a good test suite that ensures that every path in the script is taken then a dynamic approach such as this is not suitable. Of course my guess might be wrong.
From: jellybean stonerfish on 6 Mar 2010 14:51 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? Nobody gave you an answer to show all the external programs that may "possibly" be executed by a script, but if you want to find out what commands "are" executed by a script, you can put "set -x" at the beginning of the script.
From: Jerry Peters on 6 Mar 2010 16:44 zy <zyconf(a)gmail.com> wrote: > On Mar 6, 1:36�am, Icarus Sparry <use...(a)icarus.freeuk.com> wrote: >> 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. > This is indeed a problem for the question. However, fortunately all > the script that I want to parse for the moment do not contain eval. > Eval is not necessary, the command can be built via variables without using eval: cmd=ls $cmd Jerry >> 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. > I have tried this before posting. I find matching quotes correctly and > removing all the string a big task that I failed
From: zy on 6 Mar 2010 22:43 > My *guess* is that the OP wants to create a list of programs that need to > be installed, so unless he has a good test suite that ensures that every > path in the script is taken then a dynamic approach such as this is not > suitable. Of course my guess might be wrong. Your guess is indeed right. The situation is that I have some scripts written by my self that are being constantly modified introducing more prerequisites that I tend to lose track of, and I want to port the scripts to some other hosts. Unfortunately, the problem of CMD=pwd; $CMD; does exist in my script
From: zy on 6 Mar 2010 22:58 I have written a perl script to do this task. I think I can handle quotes correctly now, including those in "pwd" ; ls but these still remains a problem: var=cmd;$var or alias var='cmd' I agree that this is almost impossible to solve these in a static way. The dynamic solution is somewhat undesirable because that the scripts halt if a prerequisite is missing, and that some part of scripts are not meant to be executed without a good reason. Thanks to all you who replied, and please let me know if you have new ideas.
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 4 Prev: Fast GUI pipemeter: gprog Next: scp selected files, create directory if needed |