Since the question doesn't specify restriction to /bin/sh etc, there is the solution with ruby shell interpreter.
There is a facter ruby gem, which gives you some facts about os OS, it analyzes OS release files, other data and prints to terminal screen. You can try is as follows, begining with rubygems installation:
# apt-get install ruby rubygems
Please use the case above that is eligible for your OS. Then install the gem itself.
# gem install facter
Then use:
$ facter
NOTE: See the facter gem sources to get more info in installation.