I am writing a package manager in BASH and I would like a small snippet of code that finds lines that match exact input and count them. For example, my file contains:
xyz
xyz-lib2.0+
xyz-lib2.0
xyz-lib1.5
and "grep -c xyz" returns 4.
The current function is:
# $1 is the package name.
function check_pkg_install {
foo=$(grep -c $1 /etc/spm/packages.list)
if [ $foo -eq 1 ] ; then
pkg_installed=1
return 1
else
pkg_installed=0
return 0
fi
}
This is a summer project while I have no school, so you can take your time (but it shouldn't take 2 months...) Project is attached.