bash Shell Script – How to Check Script Dependencies

bashscriptingshell-script

Is there a method/command to check for the dependencies of a bash script?
In other words, a response to this question :
Which libraries should a user install to run the script?

I can do this manually by reading the script and check what other libraries/commands it calls but this not evident for long scripts.

Best Answer

The incredibly arcane autoconf system has been used to

produce shell scripts to automatically configure software source code packages. These scripts can adapt the packages to many kinds of UNIX-like systems without manual user intervention. Autoconf creates a configuration script for a package from a template file that lists the operating system features that the package can use, in the form of M4 macro calls.

If that is not sufficiently scary, wait until you try to write your first autoconf script. The authors of autoconf are not shy about its difficulty:

Those who do not understand Autoconf are condemned to reinvent it, poorly. The primary goal of Autoconf is making the user's life easier; making the maintainer's life easier is only a secondary goal. Put another way, the primary goal is not to make the generation of configure automatic for package maintainers; rather, the goal is to make configure painless, portable, and predictable for the end user of each autoconfiscated package. And to this degree, Autoconf is highly successful at its goal — most complaints to the Autoconf list are about difficulties in writing Autoconf input, and not in the behavior of the resulting configure.

On the other hand, you will come out of the process knowing more about the fiddly bits of various systems than you'd ever imagined existed.

These days, personally, I would assume a much more standard Debian-ish distribution was my target and not make myself write another autoconf script. I am lucky to have the luxury to choose that; you may not have such latitude.

Related Question