-2

I want to automate some installation process. For that, I need to know whether it is a DEB or RPM distribution, Im able to find some scripts for find the OS distribution.

I need to write a script to check the OS distribution and if it is CentOS, redhat, Amazon linux then print YUM. If ubuntu, Debian then print DEB.

closed as too broad by Rui F Ribeiro, Jeff Schaller May 19 at 11:31

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

0
if command -v yum >/dev/null; then
    echo 'yum is available'
fi

if command -v apt >/dev/null; then
    echo 'apt is available'
fi

This would test the availability of the yum and apt commands rather than testing for a specific distribution (there are many Linux distributions).

If you have a preference for, e.g., apt, in case both package managers are available, you could do

if command -v apt >/dev/null; then
    echo 'apt is available'
elif command -v yum >/dev/null; then
    echo 'yum is available'
else
    echo 'neither apt nor yum is avaliable'
fi

Related:

Not the answer you're looking for? Browse other questions tagged or ask your own question.