I have a script built just a way to learn bash and it uses jq
for json parsing suppose someone else downloads it and runs the file, will bash automatically prompt the user to install jq
or should I include in the script to install it?
Yes I understand that the terminal will probably throw jq: command not found
but is there a way to handle it more gracefully? Or is this how it's usually handled?
How is that do you want to install the package jq (Y/N)?
is achieved?
1 Answer
You should leave it. Typically, you would only install dependencies when creating a package for a specific package manager, not as part of a program or script.
There are so many different package managers, each with their own way of handling dependencies, and you want to let people choose which one to install with. That way they can be consistent. Otherwise, they could end up with problems like duplicate packages and incompatible versions of libraries.
Also, your script won't know how to install dependencies on all systems, even if you compile from source (some machines don't have a compiler).
You should list them in your documentation, if you have any (README file, comments, etc.)