Reputation: 25
This would be part of a reverse-engineering project.
To determine and document what a shell script (ksh, bash, sh) does, it is comfortable, if you have information about what other programs/scripts it calls.
How could one automate this task? Do you know any program or framework that can parse a shell script? This way for instance, I could recognize external command calls -- a step to the right direction.
Upvotes: 0
Views: 1070
Reputation: 116
How about:
Get a list of distinct words in that script
Search $PATH to find a hit for each
?
Upvotes: 1
Reputation: 45057
If you can't actually run the script, try loading it into a text editor that supports syntax highlighting for Bash. It will color-code all of the text and should help indicate what is a reserved word, variable, external command, etc.
Upvotes: 0
Reputation: 25416
Bash's xtrace is your friend.
You can invoke it with:
set -x
at the top of your script,bash -x
(or even bash --debugger -x
),(set -x; export SHELLOPTS; your-script; )
Upvotes: 0
Reputation: 12008
For bash/sh/ksh, I think you can easily modify their source to log what has been executed. That would be a solution.
Upvotes: 1