Is this a robust way to distinguish explicitly installed packages from those pulled in as dependencies?
When exploring the commands from this answer to my previous question, I found that the ist of packages includes a lot that were automatically installed due to dependencies. Obviously I'm interested only in those packages that I explicitly requested (the others would be pulled in automatically again, if needed).
Since I didn't figure out a way to explicitly query whether a package was installed explicitly or as dependency, I figured the best way would be to determine whether a package depends on another installed package.
This information turns out to be available with
apt-cache rdepends --installed $packagename but I still need to extract the information I need from the output.
Unfortunately the line "Reverse Depends:" is always output, even if there are no reverse dependencies. However I noticed that the dependency lines all start with a space, while the others don't. Therefore my idea is to use the following:
apt-cache rdepends --installed $packagename | grep -q "^ "
If there are no dependencies, the exit status of grep will be 1, otherwise it will be 0.
My question now is: Is this a robust way to test for this? If not, what are better ways to achieve what I want?