We are shipping some drivers for some linux for our usb products. And in our driver code to make it distribution independent we have to dynamically get the distribution name and find whether there are libraries available in each target distribution at runtime.

To do that, we need to run some commands like ldconfig, pkg-config etc etc. And this question is related to this one. So according to the answer there some distributions may have commands and it's always good to find out whether those commands are available in the distribution before executing them.

So the question is to find out whether these commands are available or not. I'm thinking about checking executable file for it's existance. for a example,

if [ -f /usr/bin/pkg-config ] ; then

Any other better way to do this ?

  • You can check which command to check.. which pkg-config Commented Sep 12, 2016 at 6:39

1 Answer 1


I would do it like this:

if type pkg-config >/dev/null 2>/dev/null; then …

But as I commented on your previous question, the pkg-config may not be available even on systems that use pkg-config. Why don't you want to ship your driver packaged according to the distribution-specific standard? Both Debian and RedHat packages have provisions to request specific libraries/versions to be installed.

Compare to the work you did in order to make your device driver the packaging even for several different distributions is nearly nothing.

  • if [ "foo$PKGCONFIG" != "foo" ]; you can also test $? to check whether which inside the command substitution succeeded (except when initializing a local variable).
    – phg
    Commented Sep 12, 2016 at 7:45
  • The problem is that our sales engineers are not into the linux , so they have little understanding about distributions and packages. When I explain them that there are different linux distributions do exist, so that's why there are more opportunities in the linux side, they are against me and they don't like that idea. They don't like to give up their wisdom "always work" into "we need to make it work". Commented Sep 14, 2016 at 7:35
  • @sandundhammika, then don't tell them that there are also QNX, VxWorks, etc;)
    – Serge
    Commented Sep 14, 2016 at 16:47
  • And, again, pkg-config is about development packages, not about binary ones.
    – Serge
    Commented Sep 14, 2016 at 16:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .